欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

UIImageView,uiimageview点击事件

来源: 开发者 投稿于  被查看 42467 次 评论:3

UIImageView,uiimageview点击事件


 

 //UIImageView 用来显示图片的控件

  UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(10,_label.frame.size.height+10+10, self.window.frame.size.width , 200)];

 //设置背景颜色

    imgView.backgroundColor = [UIColor redColor];

 

    //设置图片

    imgView.image = [UIImage imageNamed:@"m"];

 

 

 //设置圆角

 

    imgView.layer.masksToBounds = YES;

 

    imgView.layer.cornerRadius = 10;

       

 //UIImageView的填充模式

    /*图片展示形式最常用的三个

    1.UIViewContentModeScaleToFill  //根据UIImageView大小自动拉伸填满整个UIImageView,图片会变形,但还是会完整显示

    2.UIViewContentModeScaleAspectFit //图片部分适应,会拉伸图片,但是UIImageView填不满,当图片的某个边缘达到框架的宽(或高)顶部时将停止拉伸,等比拉伸,图片完整显示

    3.UIViewContentModeScaleAspectFill //可能只显示图片的某个部分,即使图片超出你的框架,配合裁剪方法(clipsToBounds)使用,图片超出的部分就会被裁减,图片没有完整显示;倘若不配合裁剪方法(clipsToBounds)使用,就可以看出它的等比拉升效果     

    */

   imgView.contentMode = UIViewContentModeScaleAspectFill;

 //截取超出范围的图片

   imgView.clipsToBounds = YES;

 

 //设置imgView是否与用户交互 

 imgView.userInteractionEnabled = YES

 

 

 //对于ImageView中的animation动画,在这里我就挑几种经常得用到的来讲

 //第一种(通过这种方法可以做出汤姆猫游戏,需要素材的留言,我发给你们)

 //(1)图片数组(animationImages)

 //要做动画的话 animationImages里面一定要装的是UIImage 不能是图片的名称字符串

 imgView.animationImages = Array;

 

 //(2)一轮动画时间的持续时间(animationDuration)

 imgView.animationDuration = 0.5;

 

 //(3)动画重复次数(animationRepeatCount)

   //0的意思是这个动画一直进行不会停下来 其他数字表示重复动画的次数

   imgView.animationRepeatCount = 0;

  

 //在以上(1)~(3)都设置好的前提下,开始动画

 [imgView startAnimating];

 

 

 //***************分割线*******************

 //第二种(通过超类UIView来调用方法)

   //动画1(开始动画)

   [UIView beginAnimations:nil context:NULL];

    //动画持续时间

    [UIView setAnimationDuration:2.0];

    //[注意]动画必须放在开始( beginAnimations)和提交(commitAnimations)中间  

 //通过手势来获取view

    UIImageView *img = (UIImageView *)tap.view;

    /*不允许单独直接修改结构体frame中的任何一个元素

    //img.frame.size.width =100;

    若要修改结构体frame中的任何一个元素,可用以下方法

    /*

 CGRect rect = img.frame;

   rect.origin.y = 0.0;

   img.frame = rect;

     */

    CGRect rect = img.frame;

 //通过创建一个rect结构体来作为中介改变其中的值

    rect.origin.y = 0.0;

 //imgView移动的最终位置

    img.frame = rect;

    //提交动画

    [UIView commitAnimations];

 

 //***************分割线*******************

 //第三种(通过超类UIView的类方法animateWithDuration: animations:执行动画

   //利用仿色变换旋转UI

    [UIView animateWithDuration:1.25 animations:^{

        UIImageView *img = (UIImageView *)tap.view;

        /*

         旋转

         参数1:在哪个基础上开始旋转

         参数2:旋转的角度

         */

        img.transform = CGAffineTransformRotate(img.transform, 90*(M_PI/180));

    }];

 

    //***************分割线****************

 //第四种(通过超类UIView的类方法

 [UIView animateWithDuration:(NSTimeInterval) animations:^(void)animations completion:^(BOOL finished)completion执行动画)

    [UIView animateWithDuration:2.0 animations:^{

        //block中为执行动画的UI

        UIImageView *img = (UIImageView *)tap.view;

   //移动动画

        img.frame = CGRectMake(0, 0, 50, 120);

    } completion:^(BOOL finished){

        //动画执行完后的回调

        UIImageView *img = (UIImageView *)tap.view;

        img.frame = CGRectMake(0,0,170,250);

   //动画执行完后就把图片移动中间

        img.center = self.window.center;

     }];

 

 

 

  以上动画方法只是个人常用的,大家可以去Xcode的内置文件中去看,还有很多,有需要的我再补充

  

 

 

 

 

 

  

用户评论