设置圆形头型并且可以点击

//有时候我们想解决一个头像问题并非只有button设置圆形,然后把图片放到button内部,还有一种方法,利用UIimageview可以加图片,并且将imageview设置为圆形,然后再i ma ge vi e w上面添加一个点击事件

例如:

 imageview1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1109@2x.png"]];//这里加一个图片

    imageview1.frame=CGRectMake(0, 0, 140, 140);

    imageview1.backgroundColor=[UIColor whiteColor];

    imageview1.layer.cornerRadius = 70;//设置为宽的一半,保证一个圆形;

    imageview1.layer.masksToBounds = YES;//去掉图片的边框;

    imageview1.userInteractionEnabled=YES;

   

    [self.view addSubview:imageview1];

    //下面就是那个点击事件

    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTaped)];

    [imageview1 addGestureRecognizer:tap1];

 

-(void)imageTaped

{

//这里面可以设置你想要做的任何事,比如页面的跳转,同时也可以讲自己的头像设置为动画类型

//动画类型如下://这个是UIview 的动画类方法,下面红色imageview就是要执行动画的view

 

         [UIView beginAnimations:@"123" context:nil];//创建动画

         [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];//动画曲线(路径)

         [UIView setAnimationDuration:1];//动画持续时间

         [UIView setAnimationRepeatCount:1];//动画循环次数

          [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:imageview1 cache:YES];//设置动画效果,以及要执行动画的view

    

        [UIView setAnimationDelegate:self];//设置动画的代理

    //下面这个方法还有一点比较好的地方就是当动画结束后可以接着调用别的方法,然后在另外一个方法内部可以做自己想干的事

        [ UIView  setAnimationDidStopSelector:@selector(animationStop)];//动画结束后调用的方法,注意设置此方法之前要先设置代理

    

    [UIView commitAnimations];//提交动画

 

}

//动画结束后调用的方法                            如右图

-(void)animationStop

{

 //这里面设置想要干的事

    NSLog(@".....");

 

}

posted @ 2015-12-28 08:44  encourageman  阅读(179)  评论(0编辑  收藏  举报