• 手势仿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
  • 相关阅读:
    bzoj3721
    [BZOJ3555] [Ctsc2014]企鹅QQ(Hash)
    [POJ3233] Matrix Power Series(矩阵快速幂)
    矩阵运算所满足的定律
    [luoguP1962] 斐波那契数列(矩阵快速幂)
    [luoguP3390]【模板】矩阵快速幂
    【转】关于LIS和一类可以用树状数组优化的DP 预备知识
    [BZOJ1264][AHOI2006]基因匹配Match(DP + 树状数组)
    [luoguP1439] 排列LCS问题(DP + 树状数组)
    蛤蛤蛤(树状数组 | 二分)
  • 原文地址:https://www.cnblogs.com/sixindev/p/4527581.html
Copyright © 2020-2023  润新知