UIImageView

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc

{

    self.window = nil;

    [super dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];

    

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    self.window.rootViewController = [[UIViewController alloc] init];

    UIImage *image = [UIImage imageNamed:@"image"];

    //创建imageview

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

    

    imageView.backgroundColor = [UIColor redColor];

    

    //设置图片

    imageView.image = image;

    imageView.layer.borderWidth = 1;

    imageView.clipsToBounds = YES;

    //停靠模式

    //imageView.contentMode = UIViewContentModeTop;

    

    

    [self.window addSubview:imageView];

    [imageView release];

    

    //通过图片来创建

    UIImageView *imageView2 = [[UIImageView alloc]initWithImage:image];

    

    imageView2.center = CGPointMake(52, 48);

    

    //[self.window addSubview:imageView2];

    [imageView2 release];

    

    //获取动态图片的数组

    NSMutableArray *images = [NSMutableArray arrayWithCapacity:4];

    for (int i = 0; i < 4; i++) {

        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Button_foot%d", i+1]];

        [images addObject:image];

}

    UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(50, 300, 100, 50)];

    //需要播放的图片

    imageView3.animationImages = images;

    //设置总播放时间

    imageView3.animationDuration = 2;

    //设置播放循环次数  缺省0 表示无限循环

    imageView3.animationRepeatCount = 0;

    

    [self.window addSubview:imageView3];

    [imageView3 release];

    //开启动画

    [imageView3 startAnimating];

    

    //停止动画

    //    [imageView3 stopAnimating];

    

    

    

    

    

    

    

    

//----------------------------------------------------------

    

//用户交互使能  默认no

    imageView3.userInteractionEnabled = YES;

    

    

    //点击手势, 不带参数

    //    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap)];

    //点击手势, 带参数

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];

    //给imageView3添加手势

    

    [imageView3 addGestureRecognizer:tap];

    [tap release];

    

    

    

    

    return YES;

}

- (void)onTap:(UITapGestureRecognizer *)tap

{

    //获取添加手势的视图

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

    [imageView stopAnimating];

}

- (void)onTap

{

    NSLog(@"tap");

}

原文地址:https://www.cnblogs.com/chunji/p/5257455.html