<span style="font-size:18px;">
//UIImage对象的初始化
/*
//第一种
// _imV = [[UIImageView alloc]initWithFrame:CGRectMake(50 , 50, 200, 300)];
// self.imV.image =[UIImage imageNamed:@"1.png"];
// _imV.backgroundColor = [UIColor redColor];
//第二种
// _imV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.png"]];
// _imV.frame = CGRectMake(50, 50, 200, 300);
*/
//第三种
//highlighted是UIImageView的一个属性.其默认值是NO.当其值是YES的时候显示高亮状态下的图片
_imV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"美女.jpg"] highlightedImage:[UIImage imageNamed:@"1.jpg"]];
_imV.frame = CGRectMake(10, 10, 300, 500);
//Image比较特殊,交互默认是关闭的,(userInteractionEnabled)是要手动打开的.
_imV.userInteractionEnabled = YES;
// self.imV.highlighted = YES;
[self addSubview:_imV];
/*
//UIImage的初始化的两种方法
//方法一
UIImage *image = [UIImage imageNamed:@"1.png"];
//方法二
NSString *str = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"];
UIImage *image1 = [UIImage imageWithContentsOfFile:str];
*/
//七大手势
//建议一个视图上只加一种手势
/*
//第一种手势(轻拍)
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
//点击多少次响应事件
// tap.numberOfTapsRequired = 1;
//用几个手指点击
// tap.numberOfTouchesRequired = 2;
[_imV addGestureRecognizer:tap];
//第二种手势(长按)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction)];
[self.imV addGestureRecognizer:longPress];
//第三种手势(旋转)
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
[_imV addGestureRecognizer:rotation];
*/
//第四种手势(捏合)
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
[_imV addGestureRecognizer:pinch];
//第五种手势(平移)
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
[_imV addGestureRecognizer:pan ];
/*
//第六种手势(轻扫)
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe)];
[_imV addGestureRecognizer:swipe];
//第七种手势(屏幕边缘识别器)
UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screen)];
screen.edges = UIRectEdgeRi ght;
[self addGestureRecognizer:screen];
*/
}
-(void)pinchAction:(UIPinchGestureRecognizer*)sender{
NSLog(@"捏合");
self.imV.transform = CGAffineTransformScale(self.imV.transform, sender.scale, sender.scale);
sender.scale = 0;
}
-(void)rotationAction:(UIRotationGestureRecognizer*)sender{
NSLog(@"旋转");
self.imV.transform = CGAffineTransformRotate(self.imV.transform, sender.rotation);
sender.rotation = 0;
}
-(void)panAction:(UIPanGestureRecognizer *)sender{
CGPoint point = [sender translationInView:self.imV];
// self.imV.transform =CGAffineTransformMakeTranslation(point.x, point.y);
self.imV.transform = CGAffineTransformTranslate(self.imV.transform, point.x, point.y);
[sender setTranslation:CGPointZero inView:self.imV];
}
/*
-(void)screen{
NSLog(@"边缘识别器");
}
-(void)swipe{
NSLog(@"轻扫");
}
-(void)panAction{
NSLog(@"平移");
}
-(void)pinchAction{
NSLog(@"捏合");
}
-(void)rotationAction{
NSLog(@"旋转");
}
-(void)longPressAction{
NSLog(@"长按");
}
-(void)tapAction{
self.imV.highlighted = !self.imV.highlighted;
// if (_imV.highlighted == YES) {
// _imV.highlighted = NO;
// }else{
// _imV.highlighted = YES;
// }
}
*/
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
</span>
UI中提供的七种手势
最新推荐文章于 2020-12-23 09:14:30 发布