• 手势仿QQ侧滑---秀清


    //
    //  SlideViewController.h
    //  qqcehua
    //
    //  Created by 张秀清 on 15/5/25.
    //  Copyright (c) 2015年 张秀清. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface SlideViewController : UIViewController
    {
        @private
        UIViewController *leftViewControl;
        UIViewController *mainViewControl;
        
        CGFloat scalef;//缩小系数
    }
    
    
    //滑动速度系数-建议在0.5-1之间。默认为0.5
    @property (assign,nonatomic) CGFloat speedf;
    
    //是否允许点击视图恢复视图位置。默认为yes
    @property (strong) UITapGestureRecognizer *sideslipTapGes;
    
    -(instancetype)initWithLeftViewController:(UIViewController *)leftViewController mainViewController:(UIViewController *)mainViewController;
    
    @end
    
    
    //
    //  SlideViewController.m
    //  qqcehua
    //
    //  Created by 张秀清 on 15/5/25.
    //  Copyright (c) 2015年 张秀清. All rights reserved.
    //
    
    #import "SlideViewController.h"
    
    @interface SlideViewController ()
    
    @end
    
    @implementation SlideViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    -(instancetype)initWithLeftViewController:(UIViewController *)leftViewController mainViewController:(UIViewController *)mainViewController
    {
        if (self = [super init])
        {
            self.speedf = 0.5;
    
            leftViewControl = leftViewController;
            mainViewControl = mainViewController;
            
            //滑动手势
            UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
            [mainViewControl.view addGestureRecognizer:pan];
            
            self.sideslipTapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
            self.sideslipTapGes.numberOfTapsRequired = 1;
            
            [mainViewControl.view addGestureRecognizer:self.sideslipTapGes];
            
            leftViewControl.view.hidden = YES;
            
            [self.view addSubview:leftViewControl.view];
            [self.view addSubview:mainViewControl.view];
        }
        return self;
    }
    
    #pragma mark - 滑动手势
    -(void)handlePan:(UIPanGestureRecognizer *)panGesture
    {
        CGPoint point = [panGesture translationInView:self.view];
        
        scalef = (point.x*self.speedf+scalef);//缩小系数
        
        if (panGesture.view.frame.origin.x >=0)//向右滑
        {
            panGesture.view.center = CGPointMake(panGesture.view.center.x + point.x*self.speedf, panGesture.view.center.y);
            /*
             CGAffineTransformIdentity,每次变换前都要置位,不然你变换用的坐标系统不是屏幕坐标系统(即绝对坐标系统),而是上一次变换后的坐标系统
             */
            panGesture.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1-scalef/1000, 1-scalef/1000);//缩小图片
            [panGesture setTranslation:CGPointMake(0, 0) inView:self.view];//移动以后的坐标
            
            leftViewControl.view.hidden = NO;
        }
        
        if (panGesture.state == UIGestureRecognizerStateEnded)
        {
            if (scalef>100*self.speedf)
            {
                [self showLeftView];
            }
            else
            {
                [self showMainView];
                scalef = 0;
            }
        }
    }
    
    #pragma mark - 单击手势
    -(void)handleTap:(UITapGestureRecognizer *)tapGesture
    {
        if (tapGesture.state == UIGestureRecognizerStateEnded) {
            [UIView beginAnimations:nil context:nil];
            tapGesture.view.transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0);
            tapGesture.view.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
            [UIView commitAnimations];
            scalef = 0;
            
        }
    }
    
    #pragma mark - 修改视图位置
    //恢复位置
    -(void)showMainView{
        [UIView beginAnimations:nil context:nil];
        mainViewControl.view.transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0);
        mainViewControl.view.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
        [UIView commitAnimations];
    }
    
    //显示左视图
    -(void)showLeftView{
        [UIView beginAnimations:nil context:nil];
        mainViewControl.view.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.8,0.8);
        mainViewControl.view.center = CGPointMake(340,[UIScreen mainScreen].bounds.size.height/2);
        [UIView commitAnimations];
        
    }
    @end
  • 相关阅读:
    批处理命令系列
    CMD批处理之PC查看连过的WIFI密码
    数据结构与算法之各种方法遍历二叉树
    二叉树同构判定算法
    卡拉兹(Callatz)猜想
    Java之字符串比较大小
    Java报错之StackOverflowError
    火绒勒索病毒诱捕技术浅析
    数据结构与算法之二叉链树
    数据结构与算法之广义表的基本运算
  • 原文地址:https://www.cnblogs.com/sixindev/p/4527581.html
Copyright © 2020-2023  润新知