// 手势识别器
// 7 个子类 : 轻拍手势 . 平移手势 . 轻扫手势 . 缩放手势 . 旋转手势 . 长按手势 . 以及 屏幕边界平移手势
// 1. 轻拍手势
UITapGestureRecognizer*tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
// 往相应的控件上添加手势
[self.rootV.Imv addGestureRecognizer:tap];
// 连击次数
//tap.numberOfTapsRequired = 2;
// 点击手指数
//tap.numberOfTouchesRequired = 2;
// UIImageView的用户交互默认是关闭的 需要打开
self.rootV.Imv.userInteractionEnabled=YES;
// 2. 长按手势
UILongPressGestureRecognizer*longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longTapAction:)];
// 设置最短长按时间
longTap.minimumPressDuration= 0.01;
[self.rootV.Imv addGestureRecognizer:longTap];
// 3. 旋转手势
UIRotationGestureRecognizer*rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction)];
// [self.rootV.Imv addGestureRecognizer:rotation];
// 4. 捏合手势
UIPinchGestureRecognizer*pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
[self.rootV.Imv addGestureRecognizer:pinch];
// 5. 平移手势
UIPanGestureRecognizer*pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction)];
//[self.rootV.Imv addGestureRecognizer:pan];
// 6. 轻扫手势
UISwipeGestureRecognizer*swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction)];
//[self.rootV.Imv addGestureRecognizer:swipe];
// 7. 屏幕边缘轻扫手势
UIScreenEdgePanGestureRecognizer*screenEdge = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenEdgeAction)];
//[self.rootV.Imv addGestureRecognizer:screenEdge];
}
- (void)tapAction:(UITapGestureRecognizer*)sender{
NSLog(@"轻拍手势");
UIImageView*temp = (UIImageView*)sender.view;
temp.image= [UIImage imageNamed:@"2"];
}
- (void)longTapAction:(UILongPressGestureRecognizer*)sender{
NSLog(@"长按手势");
if(sender.state==UIGestureRecognizerStateBegan) {
[UIView animateWithDuration:1animations:^{
CGRecttemp = sender.view.frame;
temp.size.width+= 50;
temp.size.height+=50;
sender.view.frame= temp;
}];
}elseif(sender.state==UIGestureRecognizerStateEnded){
[UIView animateWithDuration:1animations:^{
CGRecttemp = sender.view.frame;
temp.size.width-= 50;
temp.size.height-=50;
sender.view.frame= temp;
}];
}
}
- (void)rotationAction{
NSLog(@"旋转手势");
}
- (void)pinchAction:(UIPinchGestureRecognizer*)sender{
NSLog(@"捏合手势");
sender.view.transform=CGAffineTransformScale(sender.view.transform, sender.scale, sender.scale);
sender.scale= 1;
}
- (void)panAction{
NSLog(@"平移手势");
}
- (void)swipeAction{
NSLog(@"轻扫手势");
}
- (void)screenEdgeAction{
NSLog(@"屏幕边缘轻扫手势");
}
UIImageView加载动图
// 1. 声明属性
@property(nonatomic,retain)UIImageView*Image;
// 2. 初始化
self.Image = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 158, 212)];
self.Image.backgroundColor = [UIColor whiteColor];
[self addSubview:self.Image];
// 3.使用
NSMutableArray *imageArr = [NSMutableArray array];
for (int i = 1; i < 19; i ++) {
NSString *name = [NSString stringWithFormat:@"%d.tiff",i];
[imageArr addObject:[UIImage imageNamed:name]];
}
// 设置动态图图片数组
self.Image.animationImages = imageArr;
// 设置播放一次的时间
self.Image.animationDuration = 0;
// 设置重复次数
self.Image.animationRepeatCount = 0;
// 开始动画
[self.Image startAnimating];
// 结束动画
//[self.Image stopAnimating];