• 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果


    在iOS 7还没有发布的时候,各种App实现各种的swipe to pop效果,比如。

    在iOS 7上,只要是符合系统的导航结构:[即根视图由导航控制器控制]

    //  Created by wangyuanyuan on 14-9-15.
    //  Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
    //
    
    #import "AppDelegate.h"
    #import "FirstViewController.h"
    #import "SecondViewController.h"
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        FirstViewController * firstVC = [[FirstViewController alloc]init];
        SecondViewController * secondVC = [[SecondViewController alloc]init];
        
        NSArray * arr = [NSArray arrayWithObjects:firstVC,secondVC, nil];
        
        UITabBarController * tabVC = [[UITabBarController alloc]init];
        tabVC.viewControllers = arr;
        
        UINavigationController * mainVC = [[UINavigationController alloc]initWithRootViewController:tabVC];
        self.window.rootViewController = mainVC;
        
        [self.window makeKeyAndVisible];
        return YES;
    }
    

     就能够有原来漂亮的效果:

    遗憾的是目前项目代码里没有遵循iOS系统的导航结构,使得无法利用这点好处。所以我考虑使用新增的UIScreenEdgePanGestureRecognizer手势:

     1 - (void)viewWillAppear:(BOOL)animated
     2 {
     3     if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
     4         UIScreenEdgePanGestureRecognizer *left2rightSwipe = [[UIScreenEdgePanGestureRecognizer alloc]
     5                                                               initWithTarget:self
     6                                                               action:@selector(handleSwipeGesture:)];
     7         [left2rightSwipe setDelegate:self];
     8         [left2rightSwipe setEdges:UIRectEdgeLeft];
     9         [self.view addGestureRecognizer:left2rightSwipe];
    10     }
    11 
    12 }
    13 
    14 
    15 - (void)handleSwipeGesture:(UIScreenEdgePanGestureRecognizer *)gestureRecognizer
    16 {
    17     [self.navigationController popViewControllerAnimated:YES];
    18 }

    这也实现了相关的返回功能的效果,具体还有相关的手势相关的干扰问题,详情请见博客:http://blog.csdn.net/jasonblog/article/details/16867587

  • 相关阅读:
    The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the '##xp_cmdshell_proxy_account##' credential exists and contains valid information.
    SQL SERVER-创建Alwayson
    Powershell-远程操作
    powershell-将powershell脚本排到JOB
    powershell-脚本运行权限政策
    Winserver-默认以管理员运行程序
    Powershell-创建Module
    SQL SERVER-查询爆破sa密码的主机
    power-virus
    141.Linked List Cycle 快慢指针
  • 原文地址:https://www.cnblogs.com/yuanyuandachao/p/3974760.html
Copyright © 2020-2023  润新知