是否可以只允许在屏幕的某些区域滑动?例如,我有一个倒数计时器,要增加或减少它,我想随着时间的推移向左或向右滑动以增加或减少值。这可能吗?还是 UISwipGestureRecogniser 的唯一屏幕特定?
再次感谢!
-保罗。
是否可以只允许在屏幕的某些区域滑动?例如,我有一个倒数计时器,要增加或减少它,我想随着时间的推移向左或向右滑动以增加或减少值。这可能吗?还是 UISwipGestureRecogniser 的唯一屏幕特定?
再次感谢!
-保罗。
这是在预定义的 UIView 中进行滑动的代码。确保为您的视图和滑动手势制作一个 IBOutlet:
.h 文件
#import <UIKit/UIKit.h>
@interface home_1_ViewController : UIViewController <UIGestureRecognizerDelegate>
//UISwipeGestureRecognizer properties
@property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *swipeGestureRecognizerRight;
@property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *swipeGestureRecognizerLeft;
@property (strong, nonatomic) IBOutlet UIView *viewGestureCountDown;
@end
.m 文件
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeleft:)];
[left setDirection:UISwipeGestureRecognizerDirectionLeft];
[viewGestureCountDown addGestureRecognizer:left];
UISwipeGestureRecognizer *right = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwiperight:)];
[right setDirection:UISwipeGestureRecognizerDirectionRight];
[viewGestureCountDown addGestureRecognizer:right];
}
- (void)oneFingerSwipeleft:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"You swiped Left");
}
- (void)oneFingerSwiperight:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"You swiped Right");
}
感谢那些帮助提出这个问题的人。完美运行。
-保罗。
您可以尝试使用 UISwipeGestureRecognizer 检测绑定到特定视图的手势,然后将后续逻辑附加到它,例如
CGPoint point = [recognizer locationOfTouch:0 inView:MyView];