码迷,mamicode.com
首页 > 其他好文 > 详细

UIView封装的动画

时间:2014-10-22 21:47:37      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   for   sp   2014   on   log   ad   

//
//  MJViewController.m
//  10-UIView封装的动画
//
//  Created by apple on 14-4-21.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "MJViewController.h"

@interface MJViewController ()
@property (weak, nonatomic) IBOutlet UIView *myview;
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (nonatomic, assign) int index;
@end

@implementation MJViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    self.index++;
    if (self.index == 3) {
        self.index = 0;
    }
    
    NSString *filename = [NSString stringWithFormat:@"%d.jpg", self.index + 1];
    self.iconView.image = [UIImage imageNamed:filename];
    
    // 让当前view执行转场动画
    [UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromTop animations:nil completion:nil];
}

/**
 *  UIView提供的简单动画
 */
- (void)testViewSimpleAnim
{
    [UIView beginAnimations:nil context:nil];
    // 动画执行完毕后, 会自动调用self的animateStop方法
    //    [UIView setAnimationDelegate:self];// 设置动画的代理
    //    [UIView setAnimationDidStopSelector:@selector(animateStop)];// 动画执行完毕后会调用当前控制器的animateStop
    self.myview.center = CGPointMake(200, 300);
    [UIView commitAnimations];
    
    // block动画
    [UIView animateWithDuration:1.0 animations:^{
        self.myview.center = CGPointMake(200, 300);
    } completion:^(BOOL finished) {// 动画执行完了,会来到completion中
        
    }];
}

/**
 *  图层动画
 */
- (void)testLayerAnim
{
    CABasicAnimation *anim = [CABasicAnimation animation];
    anim.keyPath = @"position";
    anim.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
    anim.duration = 2.0;
    
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    anim.delegate = self;
    
    // 图层动画都是假象, 在动画执行过程中, 图层的position属性一直都没有变过
    [self.myview.layer addAnimation:anim forKey:nil];
    
    //    self.myview.layer.position == CGPointMake(0, 0)
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSLog(@"%@", NSStringFromCGPoint(self.myview.layer.position));
}

@end

UIView封装的动画

标签:io   os   ar   for   sp   2014   on   log   ad   

原文地址:http://www.cnblogs.com/xiaokanfengyu/p/4044312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!