- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//给view添加一个背景颜色
self.view.backgroundColor = [UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 335, 500)];
imageView.backgroundColor = [UIColor cyanColor];
[self.view addSubview:imageView];
[imageView release];
// //产生一个UIImage对象
//
// //通过图片名字, 创建
// UIImage *image = [UIImage imageNamed:@"i.jpg"];
//
// imageView.image = image;
//
//通过图片路径, 创建
//获取在工程文件列表中的图片路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"i" ofType:@"jpg"];
UIImage *image1 = [UIImage imageWithContentsOfFile:path];
imageView.image = image1;
//设置imageView, 让其能够响应用户交互
imageView.userInteractionEnabled = YES;
//手势,需要哪个手势就把哪部分注释解开
// //1.轻拍 Tap
// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//
// //触发这个方法的时候点击的次数
// tap.numberOfTapsRequired = 2;
//
// //需要几个手指点击
// tap.numberOfTouchesRequired = 2;
//
// [imageView addGestureRecognizer:tap];
//
// [tap release];
// //2.平移 pan
//
// UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
//
// [imageView addGestureRecognizer:pan];
// [pan release];
// //3.缩放 pinch
//
// UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
// [imageView addGestureRecognizer:pinch];
// [pinch release];
// //4.旋转 rotation
// UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
//
// [imageView addGestureRecognizer:rotation];
// [rotation release];
//
// //5.轻扫 swipe
//
// UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//
// //swipe的方向, 默认方向是向右
// swipe.direction = UISwipeGestureRecognizerDirectionLeft;
//
//
// [imageView addGestureRecognizer:swipe];
// [swipe release];
//6.长按 longPress
// UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
//
// //规定为长安手势 需要的时间, 默认是0.5秒
// longPress.minimumPressDuration = 3;
//
// //规定用户长按可移动的距离,默认是10
// longPress.allowableMovement = 100;
//
// [imageView addGestureRecognizer:longPress];
// [longPress release];
//7.屏幕边缘平移
UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenAction:)];
[imageView addGestureRecognizer:screen];
[screen release];
}
//
轻拍的方法
//- (void)tapAction:(UITapGestureRecognizer *)tap
//{
// NSLog(@"轻拍");
//}
长按的方法
//- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
//{
// //手势的状态
//
// if (longPress.state == UIGestureRecognizerStateBegan) {
// //当手势的状态处于刚开始的状态
//
// NSLog(@"长按");
// }
//
//}
//
轻扫的方法
//- (void)swipeAction:(UISwipeGestureRecognizer *)swipe
//{
// //可以通过手势的view属性 直接获取手势所在的view
// UIImageView *imageView = (UIImageView *)swipe.view;
//
// imageView.image = [UIImage imageNamed:@"71b1OOOPICb8.jpg"];
//
//
// NSLog(@"轻扫");
//}
旋转的方法
//- (void)rotationAction:(UIRotationGestureRecognizer *)rot;
//{
// NSLog(@"旋转");
// //让view跟着手势旋转
//
// rot.view.transform = CGAffineTransformRotate(rot.view.transform, rot.rotation);
// //重置弧度
// rot.rotation = 0;
//
//
//}
缩放的方法
//- (void)pinchAction:(UIPinchGestureRecognizer *)pinch;
//{
// NSLog(@"缩放");
//
// pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
//
//
//
//}
平移的方法
//- (void)panAction:(UIPanGestureRecognizer *)pan;
//{
// NSLog(@"平移");
//
// CGPoint point = [pan translationInView:pan.view];
// pan.view.transform = CGAffineTransformTranslate(pan.view.transform, point.x, point.y);
// [pan setTranslation:CGPointZero inView:pan.view];
//
//
//}
//手势的方法
- (void)screenAction:(UIScreenEdgePanGestureRecognizer *)screen
{
NSLog(@"手势");
}