cha*_*zer 5 iphone uigesturerecognizer uipangesturerecognizer uipageviewcontroller
我正在使用 UIPageViewContoller 来创建类似书籍的翻页体验。我的书的页面比 iPhone 屏幕的全宽窄 18 像素,并固定在屏幕的左侧。然后,我的 UIPageViewController 视图的框架设置为这些页面的框架大小(宽度:302,高度:460)。我这样做是为了产生书有多个页面的效果,并且翻页看起来像是从当前可见页面的边缘开始,就像 iBooks 应用程序中的体验一样。
我遇到的问题是,如果有人尝试通过从屏幕最右侧平移超过 302 px 点来翻页,则 UIPageViewController 不会捕获平移手势,并且不会翻页。我看到很多用户尝试以这种方式翻页,所以我想在不改变 UI 设计的情况下修复这种体验。
我的想法是,我可以从 UIPageViewController 外部的区域获取 UIPanGesture 并将其传递给 UIPageViewController。我已经使用作为整个视图背景的图像视图成功捕获了平移手势,但我不知道如何将手势传递给 UIPageViewController 来处理翻页。
- (void) viewDidLoad {
...
// Add a swipe gesture recognizer to grab page flip swipes that start from the far right of the screen, past the edge of the book page
self.panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:nil] autorelease];
[self.panGesture setDelegate:self];
[self.iv_background addGestureRecognizer:self.panGesture];
//enable gesture events on the background image
[self.iv_background setUserInteractionEnabled:YES];
...
}
#pragma mark - UIGestureRecognizer Delegates
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if (self.pageController.view.superview != nil) {
if (gestureRecognizer == self.panGesture) {
// we touched background of the BookViewController, pass the pan to the UIPageViewController
[self.pageController.view touchesBegan:[NSSet setWithObject:touch] withEvent:UIEventTypeTouches];
return YES; // handle the touch
}
}
return YES; // handle the touch
}
Run Code Online (Sandbox Code Playgroud)
UIPageViewController 有一个gestureRecognizers 属性。该文档似乎准确地描述了您正在寻找的内容:
\n\n\n\n手势识别器
\n\n配置为处理用户交互的 UIGestureRecognizer 对象数组。(只读)
\n\n@property(nonatomic, readonly) NSArray *gestureRecognizers
\n\n讨论
\n\n这些手势识别器最初附加到页面\n视图控制器\xe2\x80\x99s层次结构中的视图。要更改用户可以使用手势导航的屏幕区域,可以将其放置在另一个视图上。
\n\n可用性
\n\n适用于 iOS 5.0 及更高版本。申报于
\n\nUIPageViewController.h
\n
| 归档时间: |
|
| 查看次数: |
3961 次 |
| 最近记录: |