Note that there are some explanatory texts on larger screens.

plurals
  1. POtouchesbegan, touchesmoved, touchesended issue
    primarykey
    data
    text
    <p>For various reasons, I've moved these methods from a UIView subclass to my viewcontroller. And I finally got it working, except for one thing. Not only am I able to drag the UIImageviews I've programmatically created, but the actual view controllers view is draggable too. Creating this much undesired effect. I guess it's the fact that it's touches anyobject, and the background itself is an object. I'm just not sure how exclude the background. I would think that it would need the "UserInteraction enabled", but I guess not? I only want it to make UIImageViews draggable. Please forgive my noobness. I'm still learning. </p> <p>I have all the imageviews i'd want "touchable" in an NSMutableDictionary called "letterDictionary". Would it be possible to only have touch apply to what's in the dictionary? </p> <p><a href="http://imgur.com/W08dI" rel="nofollow">http://imgur.com/W08dI</a></p> <pre><code>- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *touch = [touches anyObject]; touchPoint = [touch locationInView:self.view]; movingLetter = [touch view]; CGPoint pointInside = [touch locationInView:[touch view]]; if ([movingLetter pointInside:pointInside withEvent:event]) touchedInside = YES; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (touchedInside) { UITouch *touch = [touches anyObject]; CGPoint newPoint = [touch locationInView:self.view]; // get the new touch location movingLetter.center = CGPointMake(movingLetter.center.x + newPoint.x - touchPoint.x, movingLetter.center.y + newPoint.y - touchPoint.y); touchPoint = newPoint; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (touchedInside) { UITouch *touch = [touches anyObject]; CGPoint newPoint = [touch locationInView:self.view]; movingLetter.center = CGPointMake(movingLetter.center.x + newPoint.x - touchPoint.x, movingLetter.center.y + newPoint.y - touchPoint.y); if (CGRectIntersectsRect([movingLetter frame], [placeHolder frame])) { movingLetter.center = placeHolder.center; } } touchedInside = NO; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { touchedInside = NO; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload