Ste*_*n.B 5 ios uipangesturerecognizer uicollectionview swift swift4
我有一个UICollectionView在我的UIViewController,我希望它响应UICollectionView.内部和外部的手势。默认情况下,UICollectionView它只响应它自己内部的手势,view但我怎样才能让它响应它外部的滑动view?
谢谢。
我编写了一个视图子类来完成此任务:
#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
Run Code Online (Sandbox Code Playgroud)
在界面生成器中,将包含视图的子视图设置为 TouchForwardingView,然后将集合视图分配给forwardingTarget 属性。
| 归档时间: |
|
| 查看次数: |
1128 次 |
| 最近记录: |