ViewController.h
//
// ViewController.h
// GestureTest
//
// Created by admin on 14-4-9.
// Copyright (c) 2014年 TESTC600. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *labShowInfo;
@property (strong, nonatomic) IBOutlet UIImageView *imgshow;
- (IBAction)actionTapGesturn:(id)sender;
@property (strong, nonatomic) IBOutlet UISwipeGestureRecognizer *swipeGesturn;
- (IBAction)actionSwipeGesturn:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *labback;
@property (strong, nonatomic) IBOutlet UIPinchGestureRecognizer *pinchGesturn;
@property(nonatomic, unsafe_unretained)CGFloat currentScale;
- (IBAction)actionPinch:(id)sender;
//rotation
@property (strong, nonatomic) IBOutlet UIRotationGestureRecognizer *rotationGesturn;
- (IBAction)actionRotation:(id)sender;
@property (nonatomic,unsafe_unretained)CGFloat rotationAngleInRadians;
//long press
- (IBAction)longpressGesturn:(id)sender;
//pin
@property (strong, nonatomic) IBOutlet UIPanGestureRecognizer *pinGesturn;
- (IBAction)actionPin:(id)sender;
@property (strong, nonatomic) IBOutlet UIView *panview;
@end
ViewController.m
//
// ViewController.m
// GestureTest
//
// Created by admin on 14-4-9.
// Copyright (c) 2014年 TESTC600. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//--------------------点击手势 开始
- (IBAction)actionTapGesturn:(id)sender {
self.labShowInfo.text=@"you tap gesturn";
}
//--------------------点击手势 结束
//--------------------滑动手势 开始
- (IBAction)actionSwipeGesturn:(id)sender {
self.labShowInfo.text=@"swipe gesturn";
//swipeGesturn fangxiang
if(self.swipeGesturn.state==UIGestureRecognizerStateEnded)
{
if(self.swipeGesturn.direction==UISwipeGestureRecognizerDirectionUp)
{
// up
self.labShowInfo.text=@"up swipe gesturn";
}
else if(self.swipeGesturn.direction==UISwipeGestureRecognizerDirectionDown)
{
self.labShowInfo.text=@"down swipe gesturn";
}
else if(self.swipeGesturn.direction==UISwipeGestureRecognizerDirectionLeft)
{
self.labShowInfo.text=@"left swipe gesturn";
}
else
{
self.labShowInfo.text=@"right swipe gesturn";
}
/*
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
*/
}
}
//--------------------滑动手势 结束
//--------------------旋转手势 开始
- (IBAction)actionRotation:(id)sender {
self.imgshow.transform=CGAffineTransformMakeRotation(self.rotationAngleInRadians+self.rotationGesturn.rotation);
if(self.rotationGesturn.state==UIGestureRecognizerStateEnded)
{
self.rotationAngleInRadians+=self.rotationGesturn.rotation;
}
}
//--------------------旋转手势 结束
//--------------------捏合手势 开始
- (IBAction)actionPinch:(id)sender {
if (self.pinchGesturn.state == UIGestureRecognizerStateEnded) {
if(self.pinchGesturn.scale>=3.0f)
self.currentScale = self.pinchGesturn.state;
}
else if(self.pinchGesturn.state == UIGestureRecognizerStateBegan && self.currentScale != 0.0f)
{
self.pinchGesturn.scale = self.currentScale;
}
if (self.pinchGesturn.scale !=NAN && self.pinchGesturn.scale != 0.0) {
self.pinchGesturn.view.transform = CGAffineTransformMakeScale(self.pinchGesturn.scale, self.pinchGesturn.scale);
}
}
//--------------------捏合手势 结束
//--------------------长按手势 开始
- (IBAction)longpressGesturn:(id)sender {
self.labShowInfo.text=@"long press";
}
//--------------------长按手势 结束
//--------------------拖动手势 开始
- (IBAction)actionPin:(id)sender {
if(self.pinGesturn.state==UIGestureRecognizerStateEnded)
{
CGPoint translation = [self.pinGesturn translationInView:self.view];
self.pinGesturn.view.center=CGPointMake(self.pinGesturn.view.center.x+translation.x,self.pinGesturn.view.center.y+translation.y);
[self.pinGesturn setTranslation:CGPointMake(0, 0) inView:self.view];
}
}
//--------------------拖动手势 结束
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
497




被折叠的 条评论
为什么被折叠?



