您的位置:首页 > 产品设计 > UI/UE

如何监听UIimageview的点击事件以及如何控制UIimageview显示圆形

2015-08-14 10:56 656 查看
1.监听UIimageview的点击事件,此时我们需要忘imageview上面添加一个UITapGestureRecognizer手势处理事件。

[code]- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageview=[[UIImageView alloc]init];
    imageview.userInteractionEnabled=YES;
    [self.view addSubview:imageview];
    imageview.backgroundColor=[UIColor redColor];
    imageview.frame=CGRectMake(100, 100, 70, 70);
    UITapGestureRecognizer *portraitTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageclick)];
    [imageview addGestureRecognizer:portraitTap];
}
-(void)imageclick
{
    NSLog(@"点击了imageview----");
}


其实UITapGestureRecognizer手势的其中一个,感兴趣的可以去查一下手势动作,网上太多了这里就不一一说了。我就简单列举一下:

[code]UITapGestureRecognizer  ----Tap(点一下)
UIPinchGestureRecognizer  ----Pinch(二指往內或往外拨动)
UIRotationGestureRecognizer  ----Rotation(旋转
UISwipeGestureRecognizer  ----Swipe(滑动,快速移动)
UIPanGestureRecognizer  ----Pan (拖移,慢速移动)
UILongPressGestureRecognizer  ----LongPress(长按)


2.控制UIimageview显示圆形图片,这个其实在ios7之后就普遍用到,很多软件的iamgeview都在倾向于一个圆形图片。因此,这里我们讲一下如何控制UIimageview显示圆形。

[code]- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageview=[[UIImageView alloc]init];
    imageview.userInteractionEnabled=YES;
    [self.view addSubview:imageview];
    imageview.backgroundColor=[UIColor redColor];
    imageview.frame=CGRectMake(100, 100, 70, 70);
    imageview.layer.masksToBounds=YES;
    imageview.layer.cornerRadius=70/2;
}


这样就ok了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: