Affects, touches, touches a problem

For various reasons, I have moved these methods from a subclass of UIView to my view manager. And I finally earned, except for one. Not only can I drag and drop UIImageviews that I programmatically created, but the view of real controllers is also draggable. Creating this unwanted effect. I think it is a fact that it concerns anyobject, and the background itself is an object. I'm just not sure how to rule out the background. I would think that this would require "UserInteraction enabled", but I guess not? I just want UIImageViews to drag. Please forgive me. I am still studying.

I have all the images that I would like to "sense" in an NSMutableDictionary called "letterDictionary". Is it possible to touch only what is in the dictionary?

http://imgur.com/W08dI

- (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; } 
+4
source share
2 answers

You have an opinion that has been affected,

  UITouch *touch = [touches anyObject]; touchPoint = [touch locationInView:self.view]; movingLetter = [touch view]; 

just check if this is the class you are looking for (e.g. a UIImageView ), then return

  UITouch *touch = [touches anyObject]; if (![[touch view] isKindOfClass:[UIImageView class]]) { return; } 
+2
source

In this regard: Method:

 -(void)touchesBegan:(NSSet* )touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; UITouch *touch = [touches anyObject]; _previousPoint1 = [touch previousLocationInView:self.main_uiview]; _previousPoint2 = [touch previousLocationInView:self.main_uiview]; _currentPoint = [touch locationInView:self.main_uiview]; [self touchesMoved:touches withEvent:event]; self.bezierPath = [UIBezierPath bezierPath]; [self.bezierPath moveToPoint:_currentPoint]; } 

TouchesMove Method

  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent* )event { UITouch *touch = [touches anyObject]; _previousPoint2 = _previousPoint1; _previousPoint1 = [touch previousLocationInView:self.main_uiview]; _currentPoint = [touch locationInView:self.main_uiview]; lastPoint = _currentPoint; [_bezierPath addLineToPoint:lastPoint]; // calculate mid point CGPoint mid1 = midPoint4(_previousPoint1, _previousPoint2); CGPoint mid2 = midPoint4(_currentPoint, _previousPoint1); UIGraphicsBeginImageContextWithOptions(self.bg_imageview.frame.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,brush); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineJoin(context,kCGLineJoinRound); [self.bg_imageview.image drawInRect:CGRectMake(0, 0, self.bg_imageview.frame.size.width, self.bg_imageview.frame.size.height)]; CGContextMoveToPoint(context, mid1.x, mid1.y); // Use QuadCurve is the key CGContextAddQuadCurveToPoint(context, _previousPoint1.x, _previousPoint1.y, mid2.x, mid2.y); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor); CGContextSetLineWidth(context, 3.0); CGContextStrokePath(context); self.bg_imageview.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();} 
0
source

All Articles