【发布时间】:2017-10-25 06:08:16
【问题描述】:
我在滚动视图中使用了两个滑动手势,因此我可以更改照片和放大,向左滑动正常且流畅,而向右滑动无法正常工作,多次滑动后它可能会触发一次,我正在使用这段代码:
//image zoom
self.scrollView.minimumZoomScale=1.0;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.contentSize=CGSizeMake(1280, 960);
self.scrollView.delegate=self;
self.scrollView.clipsToBounds = YES;
self.scrollView.scrollEnabled = false;
UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];
UISwipeGestureRecognizer * swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swiperight];
以及这两种处理滑动的方法
-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"LEFTtttttt");
if(index > 0 && index < _photoCount){
index = index - 1;
[self loadImage];
}
}
-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"RIGHTttttt");
if(index >= 0 && index < _photoCount - 1){
index = index + 1;
[self loadImage];
}
}
我当然搜索了一个解决方案并尝试了不同的代码但它不起作用,我添加了
[self.scrollView.panGestureRecognizer requireGestureRecognizerToFail:swiperight];
还有这个,
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
if (scrollView.zoomScale!=1.0) {
// Zooming, enable scrolling
scrollView.scrollEnabled = TRUE;
} else {
// Not zoomed, disable scrolling so gestures get used instead
scrollView.scrollEnabled = FALSE;
}
}
唯一的区别是当我添加后一个代码时,当我放大时向右滑动正常工作,而它应该在相反的情况下工作。
我是否遗漏了代码中的某些内容?
谢谢。
【问题讨论】:
标签: ios objective-c uiscrollview uigesturerecognizer