logo
down
shadow

how to add a gesture recogniser to a uiview in a collectionview cell


how to add a gesture recogniser to a uiview in a collectionview cell

By : user2951924
Date : November 18 2020, 03:49 PM
wish of those help I would move the addGesture code to the view controller so that you can handle the swipes in the view controller as well.
Change
code :
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("formQuestionCell", forIndexPath: indexPath) as QuestionCell

    let right = UISwipeGestureRecognizer(target: self, action: Selector("test:"))
    right.direction = UISwipeGestureRecognizerDirection.Left
    cell.answer.addGestureRecognizer(right) // I am assuming 'answer' is an outlet to the label you want to add a gesture recognizer to in the QuestionCell class

    return cell
}
func test(gestureRecognizer: UISwipeGestureRecognizer) {
    // Deal with swipe
}


Share : facebook icon twitter icon
Gesture Recogniser for all events

Gesture Recogniser for all events


By : OpethiaN
Date : March 29 2020, 07:55 AM
like below fixes the issue If you want to monitor all touch event then you can subclass UITapGestureRecognizer, this link should help: Monitoring all iOS touches
UICollectionView with gesture recogniser

UICollectionView with gesture recogniser


By : Sensei
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have a UICollectionView which has a long press gesture attached to it. It works fine when i'm pressing on a cell but if the touched area isn't a cell the app crashes with EXC_BREAKPOINT , collectView.indexPathForItemAtPoint(point) != nil { Solved it
Tap Gesture not working as expected when added to uiview in collectionview cell

Tap Gesture not working as expected when added to uiview in collectionview cell


By : Vaughn Peters
Date : October 17 2020, 08:10 PM
hop of those help? The problem is that in your definition of tap property, self is not the instance of the custom cell class because at the time the property is created, the object hasn't been fully initialized.
If you add:
code :
print(type(of: self))
(CustomCell) -> () -> CustomCell
CustomCell
lazy var tap: UITapGestureRecognizer = {
    let t = UITapGestureRecognizer(target: self, action: #selector(tapped))
    return t
}()
var tap: UITapGestureRecognizer {
    let t = UITapGestureRecognizer(target: self, action: #selector(tapped))
    return t
}
CollectionView cell instance (Outside of delegate) on UIView is not working swift 5

CollectionView cell instance (Outside of delegate) on UIView is not working swift 5


By : user3474008
Date : March 29 2020, 07:55 AM
like below fixes the issue I have a view called HorizontalMenuCollectionView on which I am loading the collection view. I can use it just by hooking it up with any view (From identity inspector). All are working perfectly. But now I want to set the background color of the first item cell when this view will be loaded at the beginning. But the cell background color is not changing. What am I missing here? a lot in advance. , Replace your func selectinitialCell() with the below one.
code :
func selectinitialCell() {
    menuCollectionView.performBatchUpdates({
        self.menuCollectionView.reloadData()
    }) { (finish) in
        if finish{
            let selectedIndexPath = IndexPath(row: 0, section: 0)
            self.menuCollectionView.selectItem(at: selectedIndexPath, animated: false, scrollPosition: .left)
        }
    }
}
Pass gesture/touches to another UIView if top level UIView does not receive the gesture it wants to handle?

Pass gesture/touches to another UIView if top level UIView does not receive the gesture it wants to handle?


By : Christopher Yashko
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Adding an overlay view, just to use a pan gesture, is an overkill. If you pass down all other touches from this overlay view (which is definitely possible), you will be solving the wrong problem. Instead, you can prevent the collection view from stealing pan gesture's touches form your root view. For this, after you add the pan gesture on root view, iterate through all gestures on collection view and make them require the pan gesture to fail. In below code, assume panDownGesture is the two finger pan down you have added to root view.
Related Posts Related Posts :
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • Web services issue on POST method
  • Parse.com error 'Method not allowed when Pinning is enabled.' when I use a PFQueryTableViewController subclass
  • Swift can't send URLRequest at all?
  • No Provisiong profiles with a valid signing identity were found and Failed to locate or generate matching signing assets
  • iOS: how to set httponly flag for NSHTTPCookie
  • How to get the mac address of a beacon in objective-c without knowing its UUID, major and minor values?
  • tableView is not showing data from JSON in swift
  • iTunes reject app for date of birth
  • SWIFT reporting "Extra argument in call" - works in Playground
  • save data depending on passed value in swift
  • webview not showing on full Screen of iphone 6
  • Location Notification's based on Latest iOS Feature
  • Adjusting Height of UITableViewCell
  • How to show five digit unicode in iphone
  • unwind doesn't work
  • Confusion about coordinates, frames & child nodes in SpriteKit on iOS?
  • If Statements not being recognized by Xcode
  • readonly property in RubyMotion
  • 'No available types for source 1' when the app runs on my device(IPhone 6) swift
  • IOS:Remove view when clicked in background
  • Removing "\" from URL in iOS Swift
  • iOS - Send an email automatically (NOT from user's account)
  • The usage of NSNotificationCenter in the relationship of parent and children
  • When do Apple auto-renewable subscriptions renew?
  • Unknown large spacing between x-axis label and base of plot in core-plot
  • How do I change the displayed time format after NSTimer is initiated?
  • Swift JSON breaks when [ ] are used
  • Secure Memory For Swift Objects
  • didSelectItemAtIndexPath doesn't work normally
  • Swift Documentation Comments
  • Is there a simple way to assign a value only once(first time) inside a loop/repeatedly running method?
  • Play sound in while app in background
  • If I have an embedded unrestricted webview, does that mean I have third-party content?
  • UITapGestureRecognizer on UIScrollView
  • App does not respond to hardware volume changes on iPad
  • troubleshoot asp.net web app on iOS
  • What size should my tab bar item icons be?
  • Parse.com Facebook authorize never calls completion handler
  • Implementing iAds on a SceneKit view
  • UIAccessibility and Apple Pay voice-over interaction issue
  • Getting objectForKeyedSubscript unrecognized selector when parsing data in table view
  • Execute action when back bar button of UINavigationController is pressed
  • iOS Table View - Set tag on cell or label?
  • Preferred approach for changing UITableViewCell content based on cell width
  • NSDateformatter dateFromString AnyObject
  • Type specifier for NSMutableArray?
  • iOS7 slideout drawer draggable bug
  • Fetch Core Data entity with a filtered set of child elements based on a property
  • UILabel AutoResize Swift
  • Swift - Selecting cells when having multiple custom cell-classes
  • Table View Cell Prototype from Storyboard not initializing subviews
  • Best way to implement view like map
  • Adding a tap gesture to a UIImageView to change a UILabel?
  • Minimum OS X and xcode requirements for ios 8.1 development
  • Changing the text of the Cancel button in the default TouchID dialog
  • iOS timing between taps
  • Swift: How do I link an action to a view inside of a tableViewCell?
  • Value for frame.size.height is always the same regardless of height of view
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org