FAQ Database Discussion Community


Swift Generic UIView subclass with protocol issue

ios,generics,swift,uiview,uigesturerecognizer
I have extended UIView to conform UIGestureRecognizerDelegate protocol The below code compiles let label = UILabel() let recognizer = UITapGestureRecognizer(target: label.self, action: Selector("tapGestureHandler:")) recognizer.delegate = label.self label.addGestureRecognizer(recognizer) Now I am trying to create a Generic Subclass to create different UIView subclass's class MyView<T:UIView> { init() { (T.self as T.Type).init(frame: CGRectZero)...

UIGestureRecognizer on UILabel inside UIView inside UIScrollview

ios,uiview,uiscrollview,uilabel,uigesturerecognizer
I have a programatically created UILabel that uses autolayout inside a UIView, inside a UIScrollView. Initially it is off-screen and then slides onto screen (by animating the change of the autolayout constraint constants). I am trying to add a gesture recognizer (single tap) to the UILabel but the gesture never...

UISwipeGestureRecognizer over UIButtons

ios,cocoa-touch,uibutton,uikit,uigesturerecognizer
I want swipes to be detected on the lower half of the screen. That part of the screen can have UIButtons as well. I want the swipes to take priority over the buttons (that is, if you swipe over the buttons, the buttons are ignored). But I want the buttons...

how to add gesture recognizer to ViewController and to its Children?

ios,swift,uigesturerecognizer,gesture
I am making app like in Euro Sport. My rootviewController is pageViewController which has 3 VCs. Swiping left and right you can change the VC. Next, I added sidebarmenu. I want to add gesture recognizer to the whole rootViewController. This is how I am adding gesture: self.exitPanGesture = UIPanGestureRecognizer() self.exitPanGesture.addTarget(self,...

Triangular UIImageView mask IOS

ios,objective-c,uiimageview,uigesturerecognizer
Check attached screenshot. This is What I have done. I have created UIImageView in storyboard and assign image (pink triangular image) to imageView. I have used gesture to recognize drag (right side, half of screen) event on image. Actually, I need drag event only when I click and drag from...

Gesture Recognizer Not Called

ios,swift,uigesturerecognizer
I have set up a gesture recognizer for dismissing the keyboard when the user taps outside the textfield. DismissKeyboard function does not get called. Have I set up the observer wrong or is this a different issue? Also, this is a tableview that is being tapped. Code Excerpt class CommentsViewController:...

UIButton not highlighted on border

ios,objective-c,uibutton,uigesturerecognizer
I create a UIButton programmatically using the following code: myButton = [UIButton new]; [myButton setImage:[UIImage imageNamed:@"myButtonNormal"] forState:UIControlStateNormal]; [myButton setBackgroundImage:[UIImage imageNamed:@"myButtonBackgroundNormal"] forState:UIControlStateNormal]; myButton.alpha = MY_BUTTON_ALPHA; [myButton addTarget:self action:@selector(myButtonSelector:) forControlEvents:UIControlEventTouchUpInside]; [self.parentViewController.view insertSubview:myButton atIndex:10]; Now the problem I am having is with...

UITapGestureRecognizer sender is the gesture, not the ui object

ios,xcode,swift,uigesturerecognizer
I've got a button called and I gave it a UIGestureRecognizer so that an IBAction is only run when the button is long pressed. You do this by adding a UILongPressGestureRecognizer to the button iteself. Then you control drag that gesture recognizer to a function like this: @IBAction func handleGesture(sender:...

Swift Gesture recognizers added to textfield inoperable after becomes first responder?

swift,uitextfield,uigesturerecognizer,tap
I added a tap and double tap gesture recognizer to a text field in swift, so that the single tap performs a function but the double tap actually makes the Textfield become first responder. it stops working though after the textfield becomes first responder for the first time. That is,...

xcode UITapGestureRecognizer on scrollview not calling until second tap

xcode,uiscrollview,uigesturerecognizer
I have the following code to dismiss the keyboard if the user taps the background. It works fine if the scrollview is in the PointZero position, but if the user scrolls the view and then selects the textview, it doesn't call the "dismissKeyboard' method until the 2nd background tap. On...

2 various UIPanGestureRecognizers with different directions simultaneously?

ios,uigesturerecognizer,gesture,uipangesturerecognizer,simultaneous
It is possible to pan up, down, left and right. Recognizer 1 handles vertical pans only, recognizer 2 handles horizontal pans only. Both of them are linked with the same one delegate object. Recognizer 2 is fully independent from the first one (except of only one direction from the described...

Manipulate target of UIGestureRecognizer in action function

ios,swift,uigesturerecognizer
When I click on a view, I would like for that view to change dimensions. TO do that, I need to find the view that has been clicked. Is there any way I could access the view in the function? Here is the code i've written so far var tapGesture:...

Do I need to update constraints after I change the position of a UIImageView

ios,swift,autolayout,uigesturerecognizer,uipangesturerecognizer
I am new to ios and have a UIImageView within my viewController that have constraints on it. I am also using autolayout for this app. Under a certain condition, I allow the user to move the imageView using the Pan Gesture. Do I need to update the constraints for that...

Get Window Coordinates of Touch in Gesture Recognizer in Swift?

ios,swift,uigesturerecognizer
I'm dragging a CALayer out of one UIView to another using a UIPanGestureRecognizer. In the UIGestureRecognizerState.Changed method, I am calling to move the CALayer with var touchLocation = recognizer.locationInView(recognizer.view) self.panForTranslation(touchLocation) However touchLocation is returning the CALayers position relative to it's frame, not the screen coordinates. How can I get a...

Gesture recognisers for UIImage

ios,xcode,swift,uigesturerecognizer
All, I have studied Gesture Recognisers and I have placed one in Interface builder and I am going to wire it all up. I have also enabled 'User Interaction Enabled' in IB on the UIImage. How can I make the UIImage larger according to how far the finger is swiped...

Simultaneous gesture recognition for specific gestures

swift,uigesturerecognizer
I'm trying to enable simultaneous gesture recognition but only for the UIPinchGestureRecognizer and UIRotationGestureRecognizer gestures. I don't want it to work for any other gestures. If I set the following property to true it allows all gestures to be recognized simultaneously, how can I limit it to just rotating and...

Cancel a UILongPressGestureRecognizer after a certain time

ios,objective-c,uicollectionview,uigesturerecognizer
I used a UILongPressGestureRecognizer in my UICollectionView. Now I when I hold my finger on the CollectionView items after a certain amount of time (for example 1 second), I want my UILongPressGestureRecognizer to end and execute a certain code: if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {} This is my code: - (void)viewDidLoad...

hide uitableview with swipe or gesture

ios,swift,uitableview,uigesturerecognizer
I am making navigation app on swift, and I have a half view - mapView, and a bottom half - tableView. I am looking for a way to hide tableView with down swipe(swiping top of tableView down, and it disappears. I found a way how to hide it with animation,...

How do I keep a UILongPressGestureRecognizer active while switching from a UIViewController to another

ios,objective-c,uiviewcontroller,uigesturerecognizer,uilongpressgesturerecogni
At some point in my app, a user can move a UIView after a long press on that view. This works fine. When the view passes over a specific region, the app has to switch to another UIViewController. The moving view is attached to this new controller. So far so...

Enable user interaction for gesture recognizer during UIView.animateWithDuration()

ios,swift,uiview,uigesturerecognizer,animatewithduration
I have a view (A) that holds several rectangular subviews (B). Each of these subviews have a single tap recognizer to trigger an action. The parent view A also has a single tap recognizer that calls a function on A's controller to make each of the subviews B flash in...

UIGestureRecognizer Method Keeps Getting Called

ios,uigesturerecognizer,nstimer
I am trying use various NSTimers in conjunction with a pan gesture, firing them only when the translation in view reaches a certain point in the view, and invalidating the timers when they go beyond a certain point. However, I found that even if I fire the timers within the...

Disable GestureRecognizer

ios,ipad,uigesturerecognizer,uitapgesturerecognizer
I have a simple memory game. But i want to turn off the tap function. When I use imageViewGurka1.gestureRecognizers=NO; it works, but I get the warning message: Initialization of pointer of type 'NSArray *' to null from a constant boolean expression. (what should I do to fix this warning message?)...

Add a UITapGestureReconizer to a UIImage

ios,uigesturerecognizer,uitapgesturerecognizer
I have a UITapGestureReconizer set up with my view but I only want the selector to be called when the view tapped is this picture I have. I tried adding the recognizer to the imageView both programmatically and via the storyboard but neither worked. It only works for my view....

How to detect taps on UITextView?

ios,swift,uitextview,uigesturerecognizer
I have a view that looks like this: When the user tries to enter information the keyboard covers the UITextViews I thought trying to detect a tap on the UITextView using a UIGestureRecognizer that I added to the UITextView, and then change the constraints according to the view which was...

While-loop in UILongPressGestureRecognizer not working

ios,swift,while-loop,uigesturerecognizer
I'm trying to adjust the position of my textField as I long-press my view, but for some reason the while-loop never stops running. My code looks like this: func buttonLongPressed(gestureRecognizer:UIGestureRecognizer){ if textEdit.editing == true{ self.textEdit.endEditing(true) } while gestureRecognizer.state == UIGestureRecognizerState.Began{ println("BEGAN") self.textEdit.frame = CGRectMake(0, gestureRecognizer.locationInView(self.view).y, self.view.frame.width, 44) } } I...

UILongPressGestureRecognizer on UIButton

ios,swift,uigesturerecognizer,uilongpressgesturerecogni
I have an UILongPressGestureRecognizer on UIButton. My gesture recogniser has minimum duration of 0.5 seconds. When I press and hold it I want it to fire every 0.5 seconds I press. How can I do it?

How to filter a quick multiple tap for single Tap event and double tap event

ios,uigesturerecognizer
I have below gestures setup: UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapDetected:)]; singleTap.numberOfTapsRequired = 1; [self addGestureRecognizer:singleTap]; UITapGestureRecognizer *doubleClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleClickDetected:)]; doubleClick.numberOfTapsRequired = 2; [self addGestureRecognizer:doubleClick]; [singleTap requireGestureRecognizerToFail:doubleClick]; When I quickly tap 3 times, I find that it...

UIScrollView and detecting gestures of its subview

ios,uiscrollview,uiimageview,uigesturerecognizer
I have ImageView inside ScrollView, to provide zooming. There are a few subview within ImageView, which must be draggable. Problem is that ScrollView blocked gestures of its subviews. How to solve this?

Adding gesture recognizer to UIImage, not UIImageView

ios,objective-c,uiimageview,uiimage,uigesturerecognizer
I have a UIImageView whose 'View Mode' is set to 'Aspect Fit' in Interface Builder.I want to add gesture recognizer to only my image inside of the UIImageView.To clarify what i say: I have a UIImageView whose bounds.size.width = 100; and bounds.size.height = 100; and I have a UIImage whose...

Detect number of touches

ios,uilabel,uigesturerecognizer,touchesbegan
I have a problem, In my app I have a Label and when I touch on it a method is fired, I implemented with -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event, the problem is that when I touch, the method is fired (everything is working) but I want when I touch once again...

UILongPressGestureRecognizer sending action twice

ios,swift,uigesturerecognizer,presentviewcontroller,long-press
My Long Press Gesture Recognizer is causing its action event to be executed twice? I was trying to figure out a Warning: Attempt to present VC2 on VC1 whose view is not in the window hierarchy! By using some println() tests, I found that my VC2 is being presented twice....

how to create an action for a clicked image from imageviewanimation

objective-c,animation,uiimageview,uigesturerecognizer
[SOLVED - SEE THE ANSWER] i want to have three images grouping as animation, and i can be able to click any of these three images to define an action. In the other words, i'd like to know the ways to create separate action/ event for each image in the...

get cell by known NSIndexPath swift

xcode,uitableview,swift,uigesturerecognizer
I wanted to do some feed like in Facebook. Feed i make like table view with customs cells. And added a panel in each cell, which u can drag down and find some more buttons. I added UIPanGestureRecognizer to it. The problem is that when i'm programming Gesture i cannot...

Why does the Swipe Gesture Recognizer only work once?

ios,swift,uigesturerecognizer
I set up a Swipe Gesture Recognizer and I connected it to the code, so that an UIImageView rotates when the user swipes to the left. @IBAction func swipeToLeft(sender: AnyObject) { UIView.animateWithDuration(1.0, animations: { self.image.transform = CGAffineTransformRotate(self.image.transform, -3.14159265358979 ) }) } I made sure the viewDidLoad method looked like this:...

UIPanGestureRecognizer conflicts with UIPinchGestureRecognizer's superview

ios,uiscrollview,uigesturerecognizer
I have a UIScrollView instance with a subview that has its own UIPanGestureRecognizer which is used to move the subview inside the scrollview. I would like the pinch-to-zoom feature of the scrollview to have the top priority over the pan gesture. However, this is not the case: when starting to...

Using gesture of the subclass over the gesture of the parent class

ios,swift,uiview,uigesturerecognizer
I have a class MyView subclassing UIView which is basically adding a tap gesture to the whole view. I have another class MyViewWithTextField subclassing MyView. In this view, there is a UITextField to which I added a gesture. My problem is that when I tap on the UITextField, its gesture...

UIGestureRecognizer working on parent class but not on subclass

ios,uigesturerecognizer
So I'm working on an app at work where a majority of the code written has been written by other people. So I have a class called BaseDetailViewController and another class which subclasses BaseDetailViewController called ProductViewController. I have a pinch recognizer on ProductViewController and there is a pinch recognizer on...

Enable UIPanGestureRecognizer when did longPress

ios,objective-c,uigesturerecognizer
I'd like to enable UIPanGestureRecognizer on customView when the customView did longPress. (I wish when you longPress customView, the customView will switch to "move mode", and you can move the customView by drag.) But in this code, only longPressAction: called. panAction: did not called. How do I fix it to...

Correct way to replace a default gesture recognizer in Swift

ios,xcode,swift,uitextfield,uigesturerecognizer
I'm trying to disable the default long-press gesture recognizer in a UITextField so that I can add my own long-press gesture recognizer. My code for doing this looks like this: for recognizer:UIGestureRecognizer in textField.gestureRecognizers as! [UIGestureRecognizer] { if recognizer is UILongPressGestureRecognizer{ recognizer = myCustomRecognizer } } But this gives me...

Using Gesture Recognizers

ios,iphone,swift,uigesturerecognizer
Before you respond, keep in mind I am very new to swift (last time I coded was 2 years ago and that was OBJC), and I seem to be having an error. Here's a sample of my code: init(sourceView:UIView, menuItems:Array<String>) { originView = sourceView sideBarTableViewController.tableData = menuItems animator = UIDynamicAnimator(referenceView:...

Display button on UICollectionViewCell after UILongPressGestureRecognizer

ios,swift,uigesturerecognizer,uicollectionviewcell
I have a UILongPressGestureRecognizer on a Cell from a CollectionView and I want to display a button from that (and all the others) cells after a long touch happens. Here's my code: func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell: CellController = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController...

IOS draggable objects not saving position

ios,position,uigesturerecognizer
I currently have a view which contains a number of buttons and a single text field. The users can drag the buttons around, and when finished, interact with the text field. Dragging the buttons using UIPanGestureRecognizer seems to work, however once a user interacts with the text field, all of...

SpriteKit Gesture Recognizer

objective-c,xcode6,sprite-kit,uigesturerecognizer
Hi I'm trying to use gesture recognizer with my sprite kit game , i wrote this code @interface GameScene() <UIGestureRecognizerDelegate>{ UISwipeGestureRecognizer *swipeGestureLeft; ISwipeGestureRecognizer *swipeGestureRight; } @end @implementation GameScene -(id)initWithSize:(CGSize)size{ if(self = [ super initWithSize:size]){ } return self; } -(void)didMoveToView:(SKView *)view{ swipeGestureLeft = [[UIGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)]; [swipeGestureLeft...

Xamarin UISwipeGestureRecognizer Renderer

c#,monotouch,uigesturerecognizer,xamarin.forms
In Xamarin.Forms I want to be able to swipe left and right to navigate a list of pictures. At the moment I just want to be able to fire an event each time a swipe is detected. child class to be used in the renderer: public class LRMasterDetailPage : ContentView...

getting error GestureRecognizer with UIImageview in swift

ios,iphone,swift,uiimageview,uigesturerecognizer
i am using 20 uiimageview so i have given tag value of each imageview now i want to add GestureRecognizer on each image view for index in 0 ... fields.count - 1{ let gestureRecognizer = UITapGestureRecognizer(target: self, action: "fieldsTappedAction") gestureRecognizer.numberOfTapsRequired = 1 println(fields[index]) fields[index].addGestureRecognizer(gestureRecognizer) } now i am trying to...

UIGestureRecognizer Delegate method is never called

ios,objective-c,uigesturerecognizer
Trying to make some draggable images in a subview of a scrollview. But nothing happens. Anybody got any ideas why a breakpoint in handlePan is never hit? :'( Thanks if u can help! -(void) viewWillAppear:(BOOL)animated { twView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"twitter"]]; [self.springView addSubview:twView]; [twView setFrame:CGRectMake(100, 100, 60, 60)]; fbView...

GestureRecognizer only works on one cell

ios,objective-c,uitableview,uigesturerecognizer
I am trying to get my cells swipeable with a gestureRecognizer : - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell Identifier"; self.cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Fetch Bookmark NSDictionary *bookmark = [self.bookmarks objectAtIndex:indexPath.row]; // Configure Cell self.cell.textLabel.numberOfLines = 0; self.cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; self.cell.textLabel.text = [bookmark...

UIGestureRecognizer on a rounded view

ios,objective-c,uigesturerecognizer,rounded-corners,uipangesturerecognizer
I have a UIView and I use below code to make it round. [myView setBackgroundColor:[UIColor redColor]]; [[myView layer] setCornerRadius:[myView bounds].size.height / 2.0f]; [[myView layer] setMasksToBounds:YES]; [myView setClipsToBounds:YES]; Then add UIPanGestureRecognizer to move the box UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(boxIsMoving:)]; [myView addGestureRecognizer:panGesture]; But the problem is when user tap outside of...

Swift - How to ask UIGestureRecognizer function to return value

swift,mkmapview,uigesturerecognizer
I would like to ask function annotation to return the coordinate (CLLocationCoordinate2D) for other function to use, here's my partial code: // ULMap is MapView. override func viewDidLoad() { var longPressGR = UILongPressGestureRecognizer(target: self, action: "annotation:") longPressGR.minimumPressDuration = 1 UImap.addGestureRecognizer(longPressGR) } func annotation(gesture: UIGestureRecognizer){ //Coordinate var touchPoint = gesture.locationInView(self.UImap) var...

How to zoom on UIView

ios,uigesturerecognizer
In my iOS app I want my users to be able to zoom in on the screen. My main uiview contains several subviews which contain images. I want my uipinchgesturerecognizer to either change the scale, or ideally use some "zoom" rather than scaling each subview. Please and thank you....

Adding longpress gesture on moving uitableviewcells between sections

objective-c,uitableview,uigesturerecognizer,long-press
Following on from my earlier question moveRowAtIndexPath - Moving cells between sections I have been able to do a traditional moveRowAtIndexPath for moving cells between sections, ie: Move Mark from Sales to Marketing. However now I would like to go one step further and add longpress gesture on the tableview...

iOS infinitely deeply nested TableView/UIGestureRecognizer view tree AND iPAD requires 2 finger scrolling on a tableview

ios,objective-c,uitableview,ipad,uigesturerecognizer
I've been trying to solve this problem for few days now and google/SO has not helped me. When viewing a tableview from an iPAD, it requires 2 finger pan gesture to scroll the tableview (only if the user interaction of the cells is enabled) A friend of mine suggested that...

UISwipeGestureRecognizer interferes with slider

ios,objective-c,uigesturerecognizer
I have a view in an iOS application (Obj-C) which has an image view in the centre, and immediately below that a slider. The image view shows album artwork, and the slider can be used to adjust the now-playing track position. There is also a pair of left and right...

Splitting game screen into right and left touch?

ios,swift,uigesturerecognizer,gesture
So I am new to Swift and I am trying to figure out how to split the screen basically in half and make it so that if the right side of the screen is tapped then the object will move over to the right and if the left side of...