zoukankan      html  css  js  c++  java
  • 手势仿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
  • 相关阅读:
    MOSS中的WebPart开发
    坚持学习WF(8):本地服务之调用外部方法
    坚持学习WF(9):本地服务之事件处理
    MOSS中如何自定义WebService
    uHub 0.4.1 发布,ADC 网络枢纽
    电商网站的宕机案例分析
    JID 2.0.1 发布,高性能的 Java 序列化库
    YaCy 1.2 发布,基于P2P的分布式Web搜索引擎
    Notepad++ 6.2.0 正式版
    Windows上 IE10 最快,Mac上Chrome 19最快
  • 原文地址:https://www.cnblogs.com/sixindev/p/4527581.html
Copyright © 2011-2022 走看看