UI手势
2015-12-07 21:17
323 查看
#import "RootViewController.h"
@interface
RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//自定义一张图片
UIImageView *picture = [[UIImageView
alloc]initWithFrame:CGRectMake(50,
100, 300,
300)];
picture.image = [UIImage
imageNamed:@"053e01451f7f39e5d4c53d20d8998672.jpg"];
picture.userInteractionEnabled =
YES;
[self.view
addSubview:picture];
[picture
release];
/*******************
手势 ******************/
//轻拍(Tap)
/*
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//设置轻拍次数 (默认1)
tap.numberOfTapsRequired = 2;
//设置轻拍的手指个数 (默认1)
tap.numberOfTouchesRequired = 2;
[picture addGestureRecognizer:tap];
[tap release];
*/
/*
//轻扫(Swipe)
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//设置轻扫方向
#warning 注意:
水平或者垂直方向只能选择一个方向.
swipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight ;
//设置轻扫手指个数
swipe.numberOfTouchesRequired = 2;
[self.view addGestureRecognizer:swipe];
[swipe release];
*/
/*
//捏合(Pich)
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
[self.view addGestureRecognizer:pinch];
[pinch release];
*/
/*
//旋转(Rotation)
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
[picture addGestureRecognizer:rotation];
[rotation release];
*/
/*
//平移(Pan)
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
[picture addGestureRecognizer:pan];
[pan release];
*/
//长按 (LongPress)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer
alloc]initWithTarget:self
action:@selector(longPressAction:)];
//设置长按时间
longPress.minimumPressDuration =
2;
[picture
addGestureRecognizer:longPress];
[longPress
release];
}
-(void)tapAction:(UITapGestureRecognizer *)tap
{
NSLog(@"被轻拍");
}
-(void)swipeAction:(UISwipeGestureRecognizer *)swipe
{
NSLog(@"轻扫");
}
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch
{
//放大缩小图片
UIImageView *pic = (UIImageView *)pinch.view;
// pic.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//参数说明: 1.当前视图的transform 2.width的缩放比例 3.height的缩放比例
pic.transform =
CGAffineTransformScale(pic.transform, pinch.scale, pinch.scale);
//缩放结束之后,
将缩放比例置为1.0
pinch.scale =
1.0;
NSLog(@"捏合");
}
-(void)rotationAction:(UIRotationGestureRecognizer *)rotation
{
UIImageView *pic = (UIImageView *)rotation.view;
pic.transform =
CGAffineTransformRotate(pic.transform, rotation.rotation);
//将当前旋转位置置为零度
rotation.rotation =
0.0;
NSLog(@"旋转");
}
-(void)panAction:(UIPanGestureRecognizer *)pan
{
UIImageView *pic = (UIImageView *)pan.view;
CGPoint p = [pan translationInView:pic];
pic.transform =
CGAffineTransformTranslate(pic.transform, p.x, p.y);
// [pan setTranslation:CGPointMake(0, 0) inView:pic];
//将当前位置,
设置成起始位置
[pan setTranslation:CGPointZero
inView:pic];
NSLog(@"平移");
}
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
NSLog(@"长按");
//长按时刻
if (longPress.state ==
UIGestureRecognizerStateBegan) {
[longPress.view
removeFromSuperview];
}
}
@interface
RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
//自定义一张图片
UIImageView *picture = [[UIImageView
alloc]initWithFrame:CGRectMake(50,
100, 300,
300)];
picture.image = [UIImage
imageNamed:@"053e01451f7f39e5d4c53d20d8998672.jpg"];
picture.userInteractionEnabled =
YES;
[self.view
addSubview:picture];
[picture
release];
/*******************
手势 ******************/
//轻拍(Tap)
/*
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//设置轻拍次数 (默认1)
tap.numberOfTapsRequired = 2;
//设置轻拍的手指个数 (默认1)
tap.numberOfTouchesRequired = 2;
[picture addGestureRecognizer:tap];
[tap release];
*/
/*
//轻扫(Swipe)
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//设置轻扫方向
#warning 注意:
水平或者垂直方向只能选择一个方向.
swipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight ;
//设置轻扫手指个数
swipe.numberOfTouchesRequired = 2;
[self.view addGestureRecognizer:swipe];
[swipe release];
*/
/*
//捏合(Pich)
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
[self.view addGestureRecognizer:pinch];
[pinch release];
*/
/*
//旋转(Rotation)
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
[picture addGestureRecognizer:rotation];
[rotation release];
*/
/*
//平移(Pan)
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
[picture addGestureRecognizer:pan];
[pan release];
*/
//长按 (LongPress)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer
alloc]initWithTarget:self
action:@selector(longPressAction:)];
//设置长按时间
longPress.minimumPressDuration =
2;
[picture
addGestureRecognizer:longPress];
[longPress
release];
}
-(void)tapAction:(UITapGestureRecognizer *)tap
{
NSLog(@"被轻拍");
}
-(void)swipeAction:(UISwipeGestureRecognizer *)swipe
{
NSLog(@"轻扫");
}
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch
{
//放大缩小图片
UIImageView *pic = (UIImageView *)pinch.view;
// pic.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//参数说明: 1.当前视图的transform 2.width的缩放比例 3.height的缩放比例
pic.transform =
CGAffineTransformScale(pic.transform, pinch.scale, pinch.scale);
//缩放结束之后,
将缩放比例置为1.0
pinch.scale =
1.0;
NSLog(@"捏合");
}
-(void)rotationAction:(UIRotationGestureRecognizer *)rotation
{
UIImageView *pic = (UIImageView *)rotation.view;
pic.transform =
CGAffineTransformRotate(pic.transform, rotation.rotation);
//将当前旋转位置置为零度
rotation.rotation =
0.0;
NSLog(@"旋转");
}
-(void)panAction:(UIPanGestureRecognizer *)pan
{
UIImageView *pic = (UIImageView *)pan.view;
CGPoint p = [pan translationInView:pic];
pic.transform =
CGAffineTransformTranslate(pic.transform, p.x, p.y);
// [pan setTranslation:CGPointMake(0, 0) inView:pic];
//将当前位置,
设置成起始位置
[pan setTranslation:CGPointZero
inView:pic];
NSLog(@"平移");
}
-(void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
NSLog(@"长按");
//长按时刻
if (longPress.state ==
UIGestureRecognizerStateBegan) {
[longPress.view
removeFromSuperview];
}
}
相关文章推荐
- UIView你知道多少
- 分析UIWindow
- UIViewController的生命周期及iOS程序执行顺序
- java获取request中表单参数
- 使用UISegementControl实现简易汤姆猫程序
- UIScrollView的常用属性【UI界面的穿透效果】
- Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead.
- LeetCode---N-Queens II
- [Exception IOS 4] - could not build module 'foundation'
- ValueAnimation初级用法
- iOS系列UI篇——UITextView
- UITableViewCell 自定义手势动作
- TextField
- iOS中的UI数据持久化,沙盒
- 具有避障和寻线功能的Arduino小车
- LeetCode(96) Unique Binary Search Trees解题报告
- 协议、代理
- 产品开发
- leetcode -- Implement Queue/Stacks using Stacks/Queue -- 简单重点
- Tom-Cat