Bar*_*rtu 2 iphone scroll uiscrollview gesture swipe
我查看了其他解决方案,但我找不到适合自己的解决方案.我有一个,我UIImageView在UIScrollView那里展示大图.
我在我的UIScrollView以及左右滑动手势识别器中启用了捏合手势.
现在,scrollview的平移手势似乎禁用,(或损坏)滑动手势.我不想禁用水平或垂直滚动UIScrollView,我的照片的初始缩放太大,无法禁用水平滚动.
我想要做的是当我来到UIScrollView的边缘时触发滑动手势.
这是一些代码;
- (void)viewDidLoad
{
// recognizer for pinch gestures
UIPinchGestureRecognizer *pinchRecognizer =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
[self.myScrollView addGestureRecognizer:pinchRecognizer];
[self.myScrollView setClipsToBounds:NO];
// recognizer for swipe gestures
UISwipeGestureRecognizer *recognizer;
// left and right swipe recognizers for left and right animation
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self myScrollView] addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self myScrollView] addGestureRecognizer:recognizer];
....
Run Code Online (Sandbox Code Playgroud)
我的左侧滑动处理程序,目前左右滑动没有任何其他功能
-(void)handleLeftSwipe:(UISwipeGestureRecognizer *)recognizer
{
if(!self.tableView.hidden) self.tableView.hidden = YES;
[self showRequiredStuff];
CATransition *transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromLeft;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
Run Code Online (Sandbox Code Playgroud)
我的初始屏幕尺寸;
#define IMAGE_VIEW_WIDTH 320.0
#define IMAGE_VIEW_HEIGHT 384.0
Run Code Online (Sandbox Code Playgroud)
我使用缩放图片,使它们缩小到尽可能小,但大多数是宽图像,这种情况下启用水平滚动,并禁用垂直滚动.虽然我的滑动处理程序也是水平的.
我想我已经清楚地解释了发生了什么以及我需要什么.我已发布代码,因为我是iphone应用程序开发的新手,我都想帮助其他人看到尽可能多的代码,也许有人会指出任何糟糕的编程,我们都将从中受益.
相关解决方案的其他发现; 设定后;
@interface myViewController () <UIScrollViewDelegate>
Run Code Online (Sandbox Code Playgroud)
和
self.myScrollView.delegate = self;
Run Code Online (Sandbox Code Playgroud)
检测是否水平到达边缘
- (BOOL) hasReachedAHorizontalEdge {
CGPoint offset = self.myScrollView.contentOffset;
CGSize contentSize = self.myScrollView.contentSize;
CGFloat height = self.myScrollView.frame.size.height;
CGFloat width = self.myScrollView.frame.size.width;
if ( offset.x == 0 ||
(offset.x + width) == contentSize.width ) {
return YES;
}
return NO;
Run Code Online (Sandbox Code Playgroud)
}
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
if ( [self hasReachedAHorizontalEdge] ) {
NSLog(@"Reached horizontal edge.");
// required here
}
}
Run Code Online (Sandbox Code Playgroud)
此时,我需要禁用到达端的滚动等,如果我到达滚动的右边缘,我需要禁用右滚动,这样才会触发滑动.
我在scrollView的边缘添加了一个薄的UIView,让它们识别滑动.我无法让scrollView与另一个滑动手势识别器配合使用.这不是理想的,但它现在有效.我将不得不调查是否有一种方法来覆盖scrollView的滑动手势识别器.
诀窍是检查并查看滑动是否在边缘附近开始,然后决定是否调用scrollView或我的滑动识别器.
| 归档时间: |
|
| 查看次数: |
8311 次 |
| 最近记录: |