• iOS开发中常用的手势---边缘手势


    说明:以下方法是开发中使用的方法,有什么不对的或者好的方法,请多多指教!

    此处的边缘手势是用来控制左侧抽屉视图的弹出以及收回。

    添加手势 :

    1. 页面上有多个手势时需要遵循 UIGestureRecognizerDelegate 协议
     1 @interface HomePageViewController ()<LeftDrawerViewDelegate,UITableViewDataSource,UITableViewDelegate,SDCycleScrollViewDelegate,UIGestureRecognizerDelegate>{
     2     
     3     LeftDrawerViewViewController *_leftDrawerVC;
     4     
     5     UITableView *_tableView;
     6     
     7     UIView *_headeView;
     8     
     9     //轮播图详情展示URL数组
    10     NSMutableArray *_urlArr;
    11     
    12     BOOL _leftDrawerState;
    13     
    14     UIView *_maskView;
    15     
    16     
    17 }

    2.添加边缘手势

     1  //添加边缘手势
     2     UIScreenEdgePanGestureRecognizer *screenEdgeGesOut = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenGesOut:)];
     3     screenEdgeGesOut.edges = UIRectEdgeLeft;
     4     
     5     [self.view addGestureRecognizer:screenEdgeGesOut];
     6     
     7     UIScreenEdgePanGestureRecognizer *screenEdgeGesIn = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenGesIn:)];
     8     screenEdgeGesIn.edges = UIRectEdgeRight;
     9     
    10     [self.view addGestureRecognizer:screenEdgeGesIn];

    3.实现手势中的方法以及协议中的方法

    //控制抽屉视图弹出
    - (void)screenGesOut:(UIScreenEdgePanGestureRecognizer *)ges{ UIView *tempUV = [self.view.window viewWithTag:DRAWERTAG]; if (_leftDrawerState == NO) { _leftDrawerState = YES; _maskView = [[UIView alloc]initWithFrame:self.view.frame]; [self.view addSubview:_maskView]; _maskView.backgroundColor = [UIColor lightGrayColor]; _maskView.alpha = 0.3; [UIView animateWithDuration:0.3 animations:^{ CGPoint ptDrawer = tempUV.center; ptDrawer.x += kSCREENWIDTH *3/4; tempUV.center = ptDrawer; // tabbarcontroller视图动 CGPoint ptTabbar = self.tabBarController.view.center; ptTabbar.x += kSCREENWIDTH *3/4; self.tabBarController.view.center = ptTabbar; }]; } }
    //控制抽屉视图收回
    - (void)screenGesIn:(UIScreenEdgePanGestureRecognizer *)ges{ UIView *tempUV = [self.view.window viewWithTag:DRAWERTAG]; if(_leftDrawerState == YES){ _leftDrawerState = NO; [_maskView removeFromSuperview]; [UIView animateWithDuration:0.3 animations:^{ CGPoint ptDrawer = tempUV.center; ptDrawer.x -= kSCREENWIDTH *3/4; tempUV.center = ptDrawer; // tabbarcontroller视图动 CGPoint ptTabbar = self.tabBarController.view.center; ptTabbar.x -= kSCREENWIDTH *3/4; self.tabBarController.view.center = ptTabbar; }]; } } //页面有多个手势时 需要遵循协议-> UIGestureRecognizerDelegate 以及实现协议中的方法 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; }
  • 相关阅读:
    BZOJ3160: 万径人踪灭(FFT,回文自动机)
    BZOJ4044: [Cerc2014] Virus synthesis(回文树+DP)
    codeforces 666E. Forensic Examination(广义后缀自动机,Parent树,线段树合并)
    BZOJ3926: [Zjoi2015]诸神眷顾的幻想乡(广义后缀自动机)
    BZOJ5137: [Usaco2017 Dec]Standing Out from the Herd(广义后缀自动机,Parent树)
    BZOJ4516: [Sdoi2016]生成魔咒(后缀自动机)
    codeforces 235C. Cyclical Quest(后缀自动机)
    codeforces 204E. Little Elephant and Strings(广义后缀自动机,Parent树)
    BZOJ2119: 股市的预测(后缀数组)
    BZOJ2555: SubString(后缀自动机,LCT维护Parent树)
  • 原文地址:https://www.cnblogs.com/liu-lang/p/5778570.html
Copyright © 2020-2023  润新知