ios UIView封裝動畫

來源:互聯網
上載者:User

標籤:

 1 #import "NJViewController.h" 2  3 @interface NJViewController () 4 @property (weak, nonatomic) IBOutlet UIView *cutomView; 5  6 @end 7  8 @implementation NJViewController 9 10 - (void)viewDidLoad11 {12     [super viewDidLoad];13 14 }15 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event16 {17    18     [UIView transitionWithView:self.view duration:1.0 options:0 animations:^{19         NSLog(@"animations");20         // 要執行的動畫21         [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];22 23     } completion:^(BOOL finished) {24         NSLog(@"completion");25         // 執行完畢之後執行的動畫26     }];27 28 }29 30 - (void)test231 {32     [UIView animateWithDuration:2.0 animations:^{33         NSLog(@"動畫執行之前: %@",NSStringFromCGPoint(self.cutomView.center));34         // 需要執行動畫的代碼35         self.cutomView.center = CGPointMake(300, 300);36         37     } completion:^(BOOL finished) {38         // 動畫執行完畢之後執行的代碼39         NSLog(@"動畫執行之後: %@",NSStringFromCGPoint(self.cutomView.center));40         41     }];42 }43 44 - (void)test145 {46     // 1.建立核心動畫47     // 注意點:如果通過核心動畫改變layer的位置狀態, 表面上看上去已經改變了, 但是實質上是沒有改變的48     CABasicAnimation *anima = [CABasicAnimation animation];49     anima.keyPath = @"position";50     anima.toValue = [NSValue valueWithCGPoint:CGPointMake(300, 300)];51     52     anima.removedOnCompletion = NO;53     anima.fillMode = kCAFillModeForwards;54     55     anima.delegate = self;56     57     // 2.添加核心動畫58     [self.cutomView.layer addAnimation:anima forKey:nil];59 }60 61 - (void)animationDidStart:(CAAnimation *)anim62 {63     NSLog(@"核心動畫執行之前 %@", NSStringFromCGPoint(self.cutomView.layer.position));64 65 }66 67 - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag68 {69     NSLog(@"核心動畫執行完畢 %@", NSStringFromCGPoint(self.cutomView.layer.position));70 }71 72 - (void)test73 {74     // 1.UIVIEW封裝的動畫, 動畫執行完畢之後不會反彈75     NSLog(@"動畫執行之前: %@",NSStringFromCGPoint(self.cutomView.center));76     [UIView beginAnimations:nil context:nil];77     [UIView setAnimationDuration:2.0];78     [UIView setAnimationDelegate:self];79     [UIView setAnimationDidStopSelector:@selector(didStopAnimatino)];80     self.cutomView.center = CGPointMake(300, 300);81     [UIView commitAnimations];82     83 }84 85 - (void)didStopAnimatino86 {87     NSLog(@"動畫執行完畢 %@", NSStringFromCGPoint(self.cutomView.center));88 }89 90 91 92 93 @end

 

ios UIView封裝動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.