【非凡程序员】关于 UIImageView的旋转

对于图片控件的自动旋转在网络上有如下资料:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelay:0];
UIView *v = [self.window viewWithTag:1];
// 你想实现到的最终状态
[UIView commitAnimations];

从:

beginAnimations

到:

commitAnimations

就是完成一次完整的动画。动画,首先你要考虑持续时间,其次你要考虑起始时间。也就是 t0 和 Δt 的关系。也就是他俩:

setAnimationDuration
setAnimationDelay

两个方法的参数的量纲都是秒。

完整代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 100, 100)];
    imageView1.image = [UIImage imageNamed:@"gyy.jpg"];
    imageView1.backgroundColor = [UIColor yellowColor];
    imageView1.contentMode = UIViewContentModeScaleToFill;      // 充满
    [self.window addSubview:imageView1];
    imageView1.tag = 1;
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 300, 200, 80)];
    btn.backgroundColor = [UIColor blueColor];
    [btn addTarget:self action:@selector(animate) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:btn];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
- (void)animate
{
    NSLog(@"haha");
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelay:0];
    UIView *v = [self.window viewWithTag:1];
    v.alpha = 0;
    [UIView commitAnimations];
}

经尝试发现有些地方需要改进,而且图片是与整个界面旋转……研究中,改日放上改良代码……

你可能感兴趣的:(【非凡程序员】关于 UIImageView的旋转)