标签:
//
// RQHViewController.m
// Demo
//
// Created by apple on 15-1-5.
// Copyright (c) 2015年 __MyCompanyName__. All rights reserved.
//#import "RQHViewController.h"
@implementation RQHViewController
@synthesize smallView;- (void)viewDidLoad
{
[super viewDidLoad];
//捏合
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGesture:)];
[self.smallView addGestureRecognizer:pinch];
//滑动
UIPanGestureRecognizer *tap = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(tapGesture:)];
[self.smallView addGestureRecognizer:tap];
//旋转
UIRotationGestureRecognizer *rotain = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationGesture:)];
[self.smallView addGestureRecognizer:rotain];
//长按
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGesture:)];
[self.smallView addGestureRecognizer:longPress];
}- (void)pinchGesture:(UIPinchGestureRecognizer* )gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateChanged:
{
UIView *view = gesture.view;
view.frame = CGRectInset(view.frame, (1 - gesture.scale) *CGRectGetWidth(view.frame), (1 - gesture.scale) * CGRectGetHeight(view.frame));
[gesture setScale:1.0f];
}
break;
default:
break;
}
}- (void)tapGesture:(UIPanGestureRecognizer *)gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateChanged:
{
CGPoint point = [gesture translationInView:gesture.view];
UIView *view = gesture.view;
view.frame = CGRectOffset(view.frame, point.x, point.y);
[gesture setTranslation:CGPointZero inView:view]; }
break;
default:
break;
}
}- (void)rotationGesture:(UIRotationGestureRecognizer *)gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateChanged:
{
UIView *view = gesture.view;
view.transform = CGAffineTransformMakeRotation(gesture.rotation);
}
break;
default:
break;
}
}- (void)longPressGesture:(UILongPressGestureRecognizer *)gesture
{
switch (gesture.state) {
case UIGestureRecognizerStateBegan:
{
UIMenuItem *item = [[UIMenuItem alloc]initWithTitle:@"hi" action:@selector(reset:)];
UIMenuController* menuController = [UIMenuController sharedMenuController];
menuController.menuItems = [NSArray arrayWithObject:item];
[menuController setTargetRect:CGRectMake(gesture.view.center.x, gesture.view.center.y, 0, 0) inView:self.view];
[menuController setMenuVisible:YES animated:YES];
}
break;
default:
break;
}
}- (void)reset:(UIMenuItem *)item
{
NSLog(@"------------hehehehe");
}//longPress需要写这个方法才能显示
- (BOOL)canBecomeFirstResponder {
return YES;
}@end
标签:
原文地址:http://www.cnblogs.com/ddzfdjijie/p/4204667.html