uipangesturerecognizer

Detect collision of two UIView's in swift

妖精的绣舞 提交于 2020-01-19 16:23:29
问题 I have two UIViews on my ViewController. I added panGesture to first view and when i start moving this view the second view will move towards first view. I want to detect an event when these two views collides. Here is my code. @IBAction func dragFirstView(sender: UIPanGestureRecognizer) { let translation = sender.translationInView(self.view) dispatch_async(dispatch_get_main_queue()) { () -> Void in UIView.animateWithDuration(2.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut,

Use UIPanGestureRecognizer to drag UIView inside limited area

放肆的年华 提交于 2020-01-10 20:11:52
问题 I want to allow user to drag UIView inside a limited area of its super view. Trying the following simple code: func handlePanForImage(recognizer: UIPanGestureRecognizer) { if let myView = recognizer.view { switch (recognizer.state) { case .Changed: let translation = recognizer.translationInView(self) if insideDraggableArea(myView.center) { myView.center = CGPoint(x:recognizer.view!.center.x + translation.x, y:recognizer.view!.center.y + translation.y) recognizer.setTranslation(CGPointZero,

Moving MKCircle on MKMapview and dragging MKMapview

萝らか妹 提交于 2020-01-04 14:28:12
问题 I have a MKCircle on MKMapView. It is user-draggable, but if the user drags the area outside the circle, the map should be moving instead. - (IBAction)createPanGestureRecognizer:(id)sender { _mapView.scrollEnabled=NO; _panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(respondToPanGesture:)]; [_mapView addGestureRecognizer:_panRecognizer]; } -(void)respondToPanGesture:(UIPanGestureRecognizer*)sender { static CGPoint originalPoint; if (sender.state ==

How to fix a new textField position after panGesture?

假如想象 提交于 2020-01-04 06:24:07
问题 I need some help with a litter issue in my code. I have a view with two textField one on the top and another on the bottom, both over a imageView. I applied a Pan Gesture in both textfields to allow change their position after the user load an image. But when I show a activityView to share the new image, the textFields return the previous location. I'd like to fix them in the new location after panGesture. What can I do? Or What am I forgetting to do? This is my Pan Gesture Action @IBAction

How to restrict a moveable view by Pan gesture

会有一股神秘感。 提交于 2019-12-30 06:33:29
问题 I have a UIImageView which is moveable via a pan gesture. UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self.photoMask addGestureRecognizer:pan]; I would like to restrict the area this can be moved on screen. Rather than the user be able to drag the view right to the side of the screen, I want to restrict it by a margin of some sort. How can I do this? Also, how is this then handled when rotated? EDIT --- #pragma mark -

Drag UIButton without it shifting to center [Swift 3]

♀尐吖头ヾ 提交于 2019-12-28 18:50:10
问题 So I found out how to make a button draggable using the UIPanGestureRecognizer. But the only way I know how to do it is by storing and dragging the button by the center. The problem with this is if you try and drag the button from a corner, the button instantly shifts from the corner to the center. What I'm looking for is a solution that would keep my finger on a selected place while moving without instantly locking onto the center. The code I'm currently using: func buttonDrag(pan:

Combining a UILongPressGestureRecognizer with a UIPanGestureRecognizer

╄→尐↘猪︶ㄣ 提交于 2019-12-28 04:02:11
问题 I d'like to combine a UILongPressGestureRecognizer with a UIPanGestureRecognizer. The UIPanGestureRecognizer should start with a long press. Is there a simple way to do this? or do I really have to write my own gesture recognizer? I wan't something like on the home screen. You press on an icon and after some time the icons start wobbling. Afterwards without releasing my finger from the screen I can start dragging the icon under my finger around. 回答1: actually, you don't have to combine

How to remove panGesture after touch in swift

此生再无相见时 提交于 2019-12-24 14:43:22
问题 I have a view that recognizes both a UIPanGesture and a single tap. How do I disable the pan gesture once the view has been tapped? I have tried multiple ways but cannot seem to figure it out. Here is the last method I tried: func gestureRecognizer(singleTapRecognizer: UIGestureRecognizer?, shouldRequireFailureOfGestureRecognizer panGesture: UIPanGestureRecognizer?) -> Bool? { print("in gesture recognizer") if wasTapped == true { return true } else { return false } Thanks! 回答1: I think you're

Setting boundaries on pan gestures

ε祈祈猫儿з 提交于 2019-12-24 10:39:34
问题 I have created 5 UIViews, each with UIPanGestureRecognizers, which I then add to another UIView. All this works and I can drag each around, but I don't want them to be dragged outside the boundaries of their parent UIView. I have read that I can implement UIGestureRecognizerDelegate with the gestureRecognizerShouldBegin function to achieve this, but I can't find enough documentation on exactly how to achieve exactly what I need. Apple's documentation on this, as usual, is quite vague. My code

PAN Gesture is crashing while taking the location of touch in view in iOS

对着背影说爱祢 提交于 2019-12-23 20:06:30
问题 I just do a sample to check the pan gesture. The pan gesture is detecting and working fine. But whenever i give a secondPoint in the pan gesture like CGPoint secondPoint = [sender locationOfTouch:1 inView:self.imageView]; it is crashing. The console is giving the message *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UIPanGestureRecognizer locationOfTouch:inView:]: index (1) beyond bounds (1).' When I use panGestureRecognizer.maximumNumberOfTouches = 1;