码迷,mamicode.com
首页 > 移动开发 > 详细

ios手势识别-缩放和旋转

时间:2014-09-16 12:18:10      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   for   2014   sp   cti   log   on   

//
//  ViewController.m
//  zwj-手势识别-缩放和旋转
//
//  Created by zwj on 14-9-16.
//  Copyright (c) 2014年 zwj. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self testPinchGes];
    [self testRotationGes];
}

/**
 *测试捏合手势
 */
-(void)testPinchGes{
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc ] initWithTarget:self action:@selector(pincheView:)];
    [self.imgView addGestureRecognizer:pinch];
    pinch.delegate = self;
}
- (void)pincheView:(UIPinchGestureRecognizer *)pinch
{
//    NSLog(@"%f",pinch.scale);
    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
    pinch.scale = 1;
}

/**
 * 测试旋转手势
 */
-(void) testRotationGes{
    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc ]initWithTarget:self action:@selector(rotationView:)];
    [self.imgView addGestureRecognizer:rotation];
    rotation.delegate = self;
}

-(void)rotationView:(UIRotationGestureRecognizer *) rotation{
//    CGFloat rotationF = rotation.rotation;
//    NSLog(@"旋转%f",rotationF);
    
    rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);
    rotation.rotation = 0;
    
//    NSLog(@"1111---%@",self.view);
//    NSLog(@"2222---%@",rotation.view);
}

/**
 *  实现代理方法
 */
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
@end

ios手势识别-缩放和旋转

标签:io   os   ar   for   2014   sp   cti   log   on   

原文地址:http://www.cnblogs.com/xiaokanfengyu/p/3974613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!