UISwipeGestureRecognizer的一些问题
来源:互联网 发布:五十知天命六十是什么 编辑:程序博客网 时间:2024/06/03 20:15
今天做一个页面的 版本更新的导航显示页
层次是这样,最底下一个UIScrollView, 然后在UIScrollView 上放 uiimageView
需求是滑动到最后一页,继续往右滑动的话 就退出导航状态
用的是UISwipeGestureRecognizer 滑动状态
设置的函数一直没有调用
后面搜了下 感觉是跟UIScrollView 的滑动冲突了
加上代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES; // Recognizers of this class are the first priority
}
问题就解决了
目前理解来说 是两个空间冲突了 希望有人遇到这种情况吗 或者说出自己的看法
附上代码
imageArray为一个数组,
"http://data.and.com.cn/image/index/1.png",
"data.and.com.cn/image/index/2.png",
"data.and.com.cn/image/index/3.png"
-(void)setImageArray:(NSArray *)imageArray{
_imageArray = imageArray;
//设置引导视图的scrollview
UIScrollView * guidePageView= [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.guidePageView = guidePageView;
guidePageView.userInteractionEnabled = YES;
guidePageView.contentSize = CGSizeMake(ScreenWidth*imageArray.count, ScreenHeight);
guidePageView.bounces = NO;
guidePageView.pagingEnabled = YES;
guidePageView.showsHorizontalScrollIndicator = NO;
self.guidePageView.delegate = self;
[self.view addSubview:guidePageView];
//添加在引导视图上的多张引导图片
for (int i=0; i<imageArray.count; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, ScreenHeight)];
// NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageArray[i]]]; //得到图像数据
// UIImage *image = [UIImage imageWithData:imgData];
// imageView.image = image;
NSString * urlStr = imageArray[i];
if ([urlStr rangeOfString:@"http"].location == NSNotFound) {
NSString * lastStr = [NSString stringWithFormat:@"http://%@", urlStr];
[imageView sd_setImageWithURL:[NSURL URLWithString:lastStr] placeholderImage:[UIImage imageNamed:@"placehodle"]];
}else{
[imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"placehodle"]];
}
[self.guidePageView addSubview:imageView];
if (i == imageArray.count - 1) {
imageView.userInteractionEnabled = YES;
UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe)];
//// swipeGR.numberOfTapsRequired = 1;
// swipeGR.numberOfTouchesRequired =1;
// //设置轻扫动作的方向
swipeGR.delegate = self;
swipeGR.direction = UISwipeGestureRecognizerDirectionLeft; //UISwipeGestureRecognizerDirectionLeft
[imageView addGestureRecognizer:swipeGR];
// UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipe)];
// [imageView addGestureRecognizer:panGesture];
}
}
if (imageArray.count > 1) {
//设置引导页上的页面控制器
UIPageControl * imagePageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, ScreenHeight - 70, ScreenWidth, 50)];
self.imagePageControl = imagePageControl;
imagePageControl.currentPage = 0;
imagePageControl.numberOfPages = imageArray.count;
imagePageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
imagePageControl.currentPageIndicatorTintColor = [UIColor redColor];
[self.view addSubview:self.imagePageControl];
}
UIButton * btn = [[UIButton alloc] init];
btn.frame = CGRectMake(ScreenWidth - 65, 20, 55, 35);
[btn setBackgroundImage:[UIImage imageNamed:@"tiaoguoicon"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(swipe) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES; // Recognizers of this class are the first priority
}
//最后一张图片的手势识别
-(void)swipe{
if ([self.delegate respondsToSelector:@selector(toRootVC)]) {
[self.delegate toRootVC];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollview {
int page = scrollview.contentOffset.x / scrollview.frame.size.width;
[self.imagePageControl setCurrentPage:page];
}
- UISwipeGestureRecognizer的一些问题
- UISwipeGestureRecognizer 实现侧滑菜单的问题
- UISwipeGestureRecognizer 左右翻页问题
- UISwipeGestureRecognizer
- UISwipeGestureRecognizer
- UISwipeGestureRecognizer
- UISwipeGestureRecognizer各种手势的用法
- iOS手势之UISwipeGestureRecognizer的正确用法
- UISwipeGestureRecognizer 滑动手势方向的判定
- Swift 简单封装UISwipeGestureRecognizer + 闭包回调监听事件,便于不同场景的 UIView调用
- hbm2java的一些问题
- 用友的一些问题
- 电子商务的一些问题
- 一些问题的解答!
- 一些奇怪的问题
- 登录的一些问题
- 一些问题的解决
- C的一些问题
- 排序——归并排序
- PostgreSQL mysql limit 区别
- java jdk1.7版本的ArrayList原理解析
- python+Django的web开发实例
- 查看android程序的CPU和内存消耗情况
- UISwipeGestureRecognizer的一些问题
- 3.5 cam_data结构体详解
- HDU 2196 Computer (树形DP)
- java synchronized详解
- Unix环境编程: 进程 补充篇
- 跟我学WEBSERVICE(二)
- 知道这20个正则表达式,能让你少写1,000行代码
- Windows下通过Docker安装Tensorflow环境
- mysql 数据库的安装步骤