【发布时间】:2015-01-28 08:43:47
【问题描述】:
我只想在从屏幕边界滑动时启用 UIScrollView 的滚动。我正在使用滑动手势识别器。
这是我的代码
-(void)swipeHandlerLeft:(UISwipeGestureRecognizer *)swipeRecognizer
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
point = [swipeRecognizer locationInView:self.view];
if(swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft)
{
if (point.x > screenWidth - 10)
{
NSLog(@"Swipped Left");
_scrollView.scrollEnabled = YES;
}
else
{
_scrollView.scrollEnabled = NO;
}
}
}
-(void)swipeHandlerRight:(UISwipeGestureRecognizer *)swipeRecognizer
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
point = [swipeRecognizer locationInView:self.view];
if(swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
if (point.x < 10)
{
NSLog(@"Swipped Right");
_scrollView.scrollEnabled = YES;
}
else
{
_scrollView.scrollEnabled = NO;
}
}
}
上述代码的问题是它在滚动视图未启用之前一直有效,但一旦启用,此方法就不会被调用,我认为原因是我在 UIView 中添加了滚动视图。
任何帮助将不胜感激。
【问题讨论】:
标签: ios iphone uiscrollview uiswipegesturerecognizer swipe-gesture