#import "ViewController.h"
@interface ViewController (){
//设置垃圾桶是否为空变量,NO为满,YES为空
BOOL boolTrashEmptyFlag;
}
//定义两张图和它们容器的属性
@property (strong,nonatomic) UIImage *imageTrashFull;
@property (strong,nonatomic) UIImage *imageTrashEmpty;
@property (strong,nonatomic) UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//界面设置
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat imageViewWidth = 128;
CGFloat imageViewHeight = 128;
CGFloat imageViewTopView = 148;
CGRect frame = CGRectMake((screen.size.width - imageViewWidth)/2 , imageViewTopView, imageViewWidth, imageViewHeight);
self.imageView = [[UIImageView alloc] initWithFrame:frame];
self.imageTrashFull = [UIImage imageNamed:@"Blend Trash Full.png"];
self.imageTrashEmpty = [UIImage imageNamed:@"Blend Trash Empty"];
self.imageView.image = self.imageTrashFull;
[self.view addSubview:self.imageView];
//新建手势识别器
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(foundPan:)];
//设置手势识别器的属性1允许移动位置2最小长按时间
recognizer.minimumNumberOfTouches = 1;
recognizer.maximumNumberOfTouches = 1;
//将手势识别器关联到imageView
[self.imageView addGestureRecognizer:recognizer];
//将imageView开启用户事件
self.imageView.userInteractionEnabled = YES;
}
-(void)foundPan:(UIGestureRecognizer*)sender{
if (sender.state != UIGestureRecognizerStateEnded && sender.state != UIGestureRecognizerStateFailed) {
CGPoint location = [sender locationInView:sender.view.superview];
sender.view.center = location;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
ios开发——手势识别(Pan)
猜你喜欢
转载自blog.csdn.net/sndongcheng/article/details/81170538
今日推荐
周排行