使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
2014-05-13 09:14
459 查看
使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
RootViewController.m
处理手势:
效果如下图:
如果想与其他手势并发操作,实现如下代理即可:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
#import "RootViewController.h" @interface RootViewController ()<UIGestureRecognizerDelegate> { CGFloat _centerX; CGFloat _centerY; UIView *_backgroundView; } @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // 存储坐标 _centerX = self.view.bounds.size.width / 2; _centerY = self.view.bounds.size.height / 2; self.view.backgroundColor = [UIColor blackColor]; // 屏幕边缘pan手势(优先级高于其他手势) UIScreenEdgePanGestureRecognizer *leftEdgeGesture = \ [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftEdgeGesture:)]; leftEdgeGesture.edges = UIRectEdgeLeft; // 屏幕左侧边缘响应 [self.view addGestureRecognizer:leftEdgeGesture]; // 给self.view添加上 // 设置一个UIView用来替换self.view,self.view用来当做背景使用 _backgroundView = [[UIView alloc] initWithFrame:self.view.bounds]; _backgroundView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:_backgroundView]; // 展示的view UIView *showView_01 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)]; showView_01.tag = 0x1; showView_01.backgroundColor = [UIColor redColor]; [_backgroundView addSubview:showView_01]; } - (void)handleLeftEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture { // 获取到当前被触摸的view UIView *view = [self.view hitTest:[gesture locationInView:gesture.view] withEvent:nil]; NSLog(@"tag = %ld", (long)view.tag); if(UIGestureRecognizerStateBegan == gesture.state || UIGestureRecognizerStateChanged == gesture.state) { // 根据被触摸手势的view计算得出坐标值 CGPoint translation = [gesture translationInView:gesture.view]; NSLog(@"%@", NSStringFromCGPoint(translation)); NSLog(@"进行中"); // 进行设置 _backgroundView.center = CGPointMake(_centerX + translation.x, _centerY); } else { // 恢复设置 [UIView animateWithDuration:.3 animations:^{ _backgroundView.center = CGPointMake(_centerX, _centerY); }]; } } @end
RootViewController.m
处理手势:
效果如下图:
如果想与其他手势并发操作,实现如下代理即可:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
相关文章推荐
- 使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
- 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
- IOS 的 7 中手势的介绍 和详细使用(UIGestureRecognizer) UIScreenEdgePanGestureRecognizer
- 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
- 使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
- 记录一下UIScreenEdgePanGestureRecognizer使用问题
- 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
- UIPanGestureRecognizer UIScreenEdgePanGestureRecognizer
- UiSlider,UISegmentedControl和UIScreenEdgePanGestureRecognizer(手势:左划屏)
- UISlider和UIScreenEdgePanGestureRecognizer和简单运用,包括滑动时颜色变化,滑动按钮以及Slider按钮颜色设置
- UIScreenEdgePanGestureRecognizer 边缘触发手势 MVC模式下实现
- Objective-C-UI控件学习之UIScreenEdgePanGestureRecognizer
- 手势 UIScreenEdgePanGestureRecognizer 屏幕边缘手势
- UI ⼿势识别器UIScreenEdgePanGestureRecognizer
- UIScreenEdgePanGestureRecognizer无法响应/失效
- 25.手势识别之UIScreenEdgePanGestureRecognizer
- iOS添加边缘手势( UIScreenEdgePanGestureRecognizer)实现侧滑效果
- iOS开发-UIScreenEdgePanGestureRecognizer实战
- UIButton上使用UIEdgeInsetsMaketitle跟图片对齐
- S7 edge更新后侧屏不能使用解决方案