ipad页面滑动

时间:2010-10-14 21:18:42

标签: iphone objective-c xcode ipad

是否有标准的方法来注册页面的左或右滑动并做出相应的响应?

2 个答案:

答案 0 :(得分:5)

如果您说的是页面,我不知道您的意思,但除此之外还有UIGestureRecognizers。还有一个UISwipeGestureRecognizer。一个不那么明显(至少对我而言)的事情是,你必须创建其中两个,一个用于左边,一个用于右边滑动。只需将它们添加到UIView即可。

UISwipeGestureRecognizer *swipeLeftGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftGesture:)];
swipeLeftGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[aView addGestureRecognizer:swipeLeftGestureRecognizer];
[swipeLeftGestureRecognizer release];

UISwipeGestureRecognizer *swipeRightGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGesture:)];
[aView addGestureRecognizer:swipeRightGestureRecognizer];
[swipeRightGestureRecognizer release];

并在- (void)swipeLeftGesture:(UISwipeGestureRecognizer *)sender- (void)swipeRightGesture:(UISwipeGestureRecognizer *)sender中,您可以随心所欲。

您应该查看UIGestureRecognizer Class Reference

答案 1 :(得分:1)