gpt4 book ai didi

ios - 在 UIPageViewController 上方画一条路径

转载 作者:行者123 更新时间:2023-11-29 03:52:15 26 4
gpt4 key购买 nike

我现在正在为 children 创建一个应用程序。该应用程序使用“UIPageViewController”。 children 可以通过拖动手指在页面内画线。

问题是,当拖动到页面上方时,页面会翻转:如何禁用特定区域的页面翻转操作,以便 children 可以在那里画线?

最佳答案

在viewDidLoad中添加点击UITapGestureRecognizer

/** add gesture recognizier */
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
singleTap.numberOfTouchesRequired = 1;
singleTap.cancelsTouchesInView = NO;
singleTap.delegate = self;
[_pageController.view addGestureRecognizer:singleTap];
[singleTap release];

捕获 UITapGestureRecognizer 委托(delegate)方法。

/** recognized tap on pageviewcontroller */
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch: (UITouch *)touch
{
CGPoint touchPoint = [touch locationInView:self.view];
/** detect screen resolution */
CGRect screenBounds = [UIScreen mainScreen].bounds;

if(touchPoint.x > (screenBounds.size.width *0.15) && touchPoint.x < (screenBounds.size.width *0.75))
{
/** tap is on center */
canScroll = NO;
} else {
/** tap is on corners */
canScroll = YES;
}

/** detect the tap view */
UIView *view = [self.view hitTest:touchPoint withEvent:nil];
if([view isKindOfClass:[UIButton class]])
{
canScroll = NO;
}

return NO;
}

重写 UIPageViewController 数据源方法

/** move to previous page */
- (UIViewController *) pageViewController: (UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if(canScroll)
{
return _prevPageViewController;
}
return nil;
}

/** move to next page */
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
if(canScroll)
{
return _nextPageViewController;
}
return nil;
}

关于ios - 在 UIPageViewController 上方画一条路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16956811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com