zoukankan      html  css  js  c++  java
  • iOS手势的综合运用

    //自定义一个VIEW封装手势功能
    //  CustormView.m
    //  gesterDemoo
    //
    //  Created by ganchaobo on 13-7-13.
    //  Copyright (c) 2013年 ganchaobo. All rights reserved.
    //
    
    #import "CustormView.h"
    
    
    @interface CustormView (){
        UIView *_parentview;
        CGPoint _lastCenter;
    }
    
    @end
    
    @implementation CustormView
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
        // Initialization code
        }
        return self;
    }
    
    -(id)INitwithContetView:(UIView*)contentview ParentView:(UIView *)parentView{
        self=[super initWithFrame:contentview.bounds];
        UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [self addGestureRecognizer:tap];
        [self addGestureRecognizer:pan];
        [pan release];
        [tap release];
        _parentview=parentView;
        _lastCenter=self.center;
        return self;
        
    }
    
    -(void)pan:(UIPanGestureRecognizer *)pan{
        //移动点的位置
        CGPoint panPoint=[pan translationInView:_parentview];
        CGFloat x=pan.view.center.x+panPoint.x;
        NSLog(@"%f---->%f,--%f",panPoint.x,_lastCenter.x,x);
        if(x<_lastCenter.x){
            x=_lastCenter.x;
        }
      
    
        self.center=CGPointMake(x, _lastCenter.y);
    
        if(pan.state==UIGestureRecognizerStateEnded){
          
            [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                if(x>320){
                    self.center=CGPointMake(390, _lastCenter.y);
                }
                else{
                    self.center=_lastCenter;
                }
                
            } completion:^(BOOL finished) {
                
            }];
        }
        [pan setTranslation:CGPointZero inView:self];
    }
    
    -(void)tap:(UITapGestureRecognizer *)tap{
        NSLog(@"tap");
        [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            self.center=_lastCenter;
        } completion:^(BOOL finished) {
            
        }];
    }
    
    
    @end
    //
    //  CustormView.m
    //  gesterDemoo
    //
    //  Created by ganchaobo on 13-7-13.
    //  Copyright (c) 2013年 ganchaobo. All rights reserved.
    //
    
    #import "CustormView.h"
    
    
    @interface CustormView (){
        UIView *_parentview;
        CGPoint _lastCenter;
    }
    
    @end
    
    @implementation CustormView
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
        // Initialization code
        }
        return self;
    }
    
    -(id)INitwithContetView:(UIView*)contentview ParentView:(UIView *)parentView{
        self=[super initWithFrame:contentview.bounds];
        UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [self addGestureRecognizer:tap];
        [self addGestureRecognizer:pan];
        [pan release];
        [tap release];
        _parentview=parentView;
        _lastCenter=self.center;
        return self;
        
    }
    
    -(void)pan:(UIPanGestureRecognizer *)pan{
        //移动点的位置
        CGPoint panPoint=[pan translationInView:_parentview];
        CGFloat x=pan.view.center.x+panPoint.x;
        NSLog(@"%f---->%f,--%f",panPoint.x,_lastCenter.x,x);
        if(x<_lastCenter.x){
            x=_lastCenter.x;
        }
      
    
        self.center=CGPointMake(x, _lastCenter.y);
    
        if(pan.state==UIGestureRecognizerStateEnded){
          
            [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                if(x>320){
                    self.center=CGPointMake(390, _lastCenter.y);
                }
                else{
                    self.center=_lastCenter;
                }
                
            } completion:^(BOOL finished) {
                
            }];
        }
        [pan setTranslation:CGPointZero inView:self];
    }
    
    -(void)tap:(UITapGestureRecognizer *)tap{
        NSLog(@"tap");
        [UIView animateWithDuration:0.75 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            self.center=_lastCenter;
        } completion:^(BOOL finished) {
            
        }];
    }
    
    
    @end
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        UIView *firstview=[[UIView alloc] initWithFrame:self.view.bounds];
        firstview.backgroundColor=[UIColor redColor];
        [self.view addSubview:firstview];
        [firstview release];
    
    
        CustormView *view=[[CustormView alloc] INitwithContetView:self.view ParentView:self.view];
        view.backgroundColor=[UIColor yellowColor];
        [self.view addSubview:view];
        [view release];
    
        
        
    }

     原文地址:http://blog.csdn.net/totogo2010/article/details/8622400

  • 相关阅读:
    Python包中__init__.py作用
    获取web页面xpath
    Selenium学习(Python)
    C++构造函数的选择
    分布式实时处理系统——C++高性能编程
    构建之法(邹欣)
    分布式实时处理系统——通信基础
    go语言-csp模型-并发通道
    redis.conf 配置说明
    Linux fork()一个进程内核态的变化
  • 原文地址:https://www.cnblogs.com/gcb999/p/3189137.html
Copyright © 2011-2022 走看看