iPhone開發中關于UIView Animation實現效果
iPhone開發中關于UIView Animation實現效果是本文要介紹的內容,主要是來學習UIView Animation一連串的實現效果,具體內容我們來看本文如何實現。之前受某人影響以為一連串的UIView Animation 只能這么寫:
在某個animation 設置delegate ,然后在 delegate 函數中再調用另一個函數。
今天偷閑決定看 iPhone cookbook 代碼查漏補缺下,結果發現這代碼:
C代碼
- // Hide the bar button and show the view
- self.navigationItem.rightBarButtonItem = nil;
- [self.view viewWithTag:101].alpha = 1.0f;
- // Bounce to 115% of the normal size
- [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.4f];
- [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.15f, 1.15f);
- [UIView commitModalAnimations];
- // Return back to 100%
- [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.3f];
- [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.0f, 1.0f);
- [UIView commitModalAnimations];
- // Pause for a second and appreciate the presentation
- [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];
- // Slowly zoom back down and hide the view
- [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0f];
- [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(0.01f, 0.01f);
- [UIView commitModalAnimations];
- // Restore the bar button
- [self.view viewWithTag:101].alpha = 0.0f;
tnnd 原來可以這么寫。
同時學到個新玩意。
C代碼
- [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];
PS. 原來這個例子就叫做 Modal View Animation 罪過罪過,搞了這么久iPhone還不知道這東西。
抱歉,看錯了,原來是作者自己實現的方法,仔細一看原來
C代碼
- commitModalAnimations
具體代碼實現是這樣的。
Java代碼
- @interface UIViewDelegate : NSObject
- {
- CFRunLoopRef currentLoop;
- }
- @end
- @implementation UIViewDelegate
- -(id) initWithRunLoop: (CFRunLoopRef)runLoop
- {
- if (self = [super init]) currentLoop = runLoop;
- return self;
- }
- -(void) animationFinished: (id) sender
- {
- CFRunLoopStop(currentLoop);
- }
- @end
- @implementation UIView (ModalAnimationHelper)
- + (void) commitModalAnimations
- {
- CFRunLoopRef currentLoop = CFRunLoopGetCurrent();
- UIViewDelegate *uivdelegate = [[UIViewDelegate alloc] initWithRunLoop:currentLoop];
- [UIView setAnimationDelegate:uivdelegate];
- [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
- [UIView commitAnimations];
- CFRunLoopRun();
- [uivdelegate release];
- }
- @end
小結:iPhone開發中關于UIView Animation實現效果的內容介紹完了,希望通過本文的學習能對你有所幫助!