swipetableviewcell swipecellkit swipecell swipeable kit ios swift uicollectionview swift4 uipangesturerecognizer

ios - swipecellkit - Cómo hacer que una vista de colección responda a gestos de panorámica fuera de su propia vista



swipetableviewcell (3)

Escribí una subclase de vista que logra solo esto:

#import <UIKit/UIKit.h> @interface TouchForwardingView : UIView @property (nonatomic, weak) IBOutlet UIResponder *forwardingTarget; - (instancetype)initWithForwardingTarget:(UIResponder *)forwardingTarget; @end #import "TouchForwardingView.h" @implementation TouchForwardingView - (instancetype)initWithForwardingTarget:(UIResponder *)forwardingTarget { self = [super init]; if (self) { self.forwardingTarget = forwardingTarget; } return self; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; [self.forwardingTarget touchesBegan:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesEnded:touches withEvent:event]; [self.forwardingTarget touchesEnded:touches withEvent:event]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesCancelled:touches withEvent:event]; [self.forwardingTarget touchesCancelled:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; [self.forwardingTarget touchesMoved:touches withEvent:event]; } @end

En el generador de interfaz, configure la subvista de la vista que contiene a TouchForwardingView, luego asigne la vista de colección a la propiedad forwardingTarget.

Tengo un UICollectionView en mi UIViewController y quiero que responda a los gestos dentro y fuera de UICollectionView . Por defecto, UICollectionView solo responde a los gestos dentro de su propia view pero ¿cómo puedo hacer que responda a golpes fuera de su view ?

Gracias.


Swift versión de Nailer''s anwer, esto reenviará todos los gestos realizados en viewcontroller a la colección

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { collectionView.touchesBegan(touches, withEvent: event) } override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { collectionView.touchesEnded(touches, withEvent: event) } override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) { collectionView.touchesCancelled(touches, withEvent: event) } override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { collectionView.touchesMoved(touches, withEvent: event) }


La respuesta de Steven B para Swift 4 :)

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { collectionView.touchesBegan(touches, with: event) } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { collectionView.touchesEnded(touches, with: event) } override func touchesCancelled(_ touches: Set<UITouch>?, with event: UIEvent?) { collectionView.touchesCancelled(touches!, with: event) } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { collectionView.touchesMoved(touches, with: event) }