• UIView动画


    IOS动画的实现方式多种多样,这里就仅仅记录一下 beginAnimations:context 。

    在你调用 beginAnimations:context:方法来启动一个动画后,动画并不会马上被运行,直 到你调用 UIView 类的 commitAnimations 类方法。你对一个视图对象运行的介于 beginAnimations:context:方法跟 commitAnimations方法之间的操作(比如移动)会在 commitAnimations 被运行后才会生效 。

    代码非常easy,直接贴了,例如以下:

    //
    //  ViewController.m
    //  Graphics
    //
    //  Created by aaron on 14b-5-29.
    //  Copyright (c) 2014年 The Technology Studio. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    @property(nonatomic,strong) UIImageView *imageView1;
    @property(nonatomic,strong) UIImageView *imageView2;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        UIImage *image = [UIImage imageNamed:@"1.png"];
        self.imageView1 = [[UIImageView alloc] initWithImage:image];
        self.imageView2 = [[UIImageView alloc] initWithImage:image];
        [self.imageView1 setFrame:CGRectMake(0.0f,
                                             0.0f,
                                             100.0f,
                                             100.0f)];
       
        [self.imageView2 setFrame:CGRectMake(220.0f,
                                             350.0f,
                                             100.0f,
                                             100.0f)];
        [self.view addSubview:self.imageView1];
        [self.view addSubview:self.imageView2];
        
    //    [self startTopLeftImageViewAnimation];
    //    [self startBottomRightViewAnimationAfterDelay:2];
        [self affineTransformScaleAnimation];
        [self affineTransformRotateAnimation];
        
    }
    
    //imageView2 animation
    -(void)startTopLeftImageViewAnimation{
        [self.imageView1 setFrame:CGRectMake(0.0f,
                                             0.0f,
                                             100.0f,
                                             100.0f)];
        [self.imageView1 setAlpha:1.0f];
        [UIView beginAnimations:@"imageView1Animation" context:(__bridge void*)self.imageView1];
        [UIView setAnimationDuration:3.0f];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)];
        [self.imageView1 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)];
        [self.imageView1 setAlpha:0.0f];
        [UIView commitAnimations];
    }
    
    -(void)imageViewDidStop:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{
        NSLog(@"AnimationID = %@
    ",paramAnimationID);
        UIImageView *contextImageView = (__bridge UIImageView *)(paramContext);
        NSLog(@"contextImageView = %@",contextImageView);
        [contextImageView removeFromSuperview];
    }
    
    
    //imageView2 animation
    -(void)startBottomRightViewAnimationAfterDelay:(CGFloat)paramDelay{
        [self.imageView2 setFrame:CGRectMake(220.0f,
                                             350.0f,
                                             100.0f,
                                             100.0f)];
        [self.imageView2 setAlpha:1.0f];
        [UIView beginAnimations:@"imageView2Animation" context:(__bridge void *)(self.imageView2)];
        [UIView setAnimationDuration:3.0f];
        [UIView setAnimationDelay:paramDelay];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)];
        [self.imageView2 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
        [self.imageView2 setAlpha:0.0f];
        [UIView commitAnimations];
    }
    
    
    //imageView1 AffineTransformScale animation
    -(void)affineTransformScaleAnimation{
        self.imageView1.center = self.view.center;
        self.imageView1.transform = CGAffineTransformIdentity;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:5.0f];
        self.imageView1.transform = CGAffineTransformMakeScale(2.0f, 2.0f);
        [self.imageView1 setAlpha:0.0f];
        [UIView commitAnimations];
    }
    
    //imageView2 AffineTransformRotate animation
    -(void)affineTransformRotateAnimation{
        self.imageView2.center = self.view.center;
        [UIView beginAnimations:@"clockwiseAnimation" context:NULL];
        [UIView setAnimationDuration:5.0f];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(clockwiseRotationStopped:finished:context:)];
        self.imageView2.transform = CGAffineTransformMakeRotation(90.0f*M_PI/180.f);
        [UIView commitAnimations];
    }
    
    
    -(void)clockwiseRotationStopped:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{
        [UIView beginAnimations:@"counterclockwiseAnimation" context:NULL];
        [UIView setAnimationDuration:5.0f];
        self.imageView2.transform = CGAffineTransformIdentity;
        [UIView commitAnimations];
    }
    
    @end
    

    执行效果例如以下:


  • 相关阅读:
    url传参数出现乱码解决方法
    ASP.NET 当GridView中没有数据的时候,显示标题栏 并且给出一行数据提
    纯手工打造 IFAN (光盘回收及午餐筷子回收事业)
    javascript 收集
    Winform 中的控件透明设置要点
    对指定的网页进行截图 C#版
    生成短GUID的两个方法
    按键相关的 JS脚本代码
    ISCSI Enterprise Target 的其他资源和地址
    ORA01403:no data found 解决方法两则
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7191216.html
Copyright © 2020-2023  润新知