自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Xcode學習之視圖轉(zhuǎn)換例子實踐

移動開發(fā) iOS
本文介紹的是Xcode學習之視圖轉(zhuǎn)換例子實踐,講述了xcode中視圖轉(zhuǎn)換例子實踐的內(nèi)容,先來看詳細內(nèi)容。

Xcode學習之視圖轉(zhuǎn)換例子實踐是本文要介紹的內(nèi)容,主要介紹了xcode視圖轉(zhuǎn)換例子實踐的教程。讓我們進一步的去學習xcode的相關(guān)內(nèi)容,先來看本文詳細介紹。

翻轉(zhuǎn)(類似翻書)視圖效果,兩種實現(xiàn)方式

滑動視圖效果

分別看各自實現(xiàn)的重點:

翻轉(zhuǎn)視圖效果例子

在官方上,提供

  1. UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight 

方法,來實現(xiàn)視圖向左或向右翻轉(zhuǎn)。

在UIView動畫塊中使用轉(zhuǎn)換,需要2個工作:

1、必須將轉(zhuǎn)換作為塊參數(shù)添加

2、應(yīng)該在塊內(nèi)部重新安排視圖順序。

效果代碼如下:

  1. - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{      
  2. // Start Animation Block     
  3.  CGContextRef context = UIGraphicsGetCurrentContext();      
  4.  [UIView beginAnimations:nil context:context];      
  5.  [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];  
  6.  //*    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];      
  7.  [UIView setAnimationDuration:1.0];         
  8.  // Animations    [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];  
  9.  //*         
  10.  // Commit Animation Block      
  11.  [UIView commitAnimations];  
  12.  } 

注意,此代碼寫在touchesEnded事件上的,也是符合翻轉(zhuǎn)邏輯

上述代碼中帶有//*的地方,就是所需2個工作。

***處表示向左翻轉(zhuǎn),翻轉(zhuǎn)的對象是當前視圖的上級視圖,并緩存

第二處表示子視圖集合中,0和1之間交換

UIView類

類方法:(動畫部分)

  1. setAnimationTransition:forView:cache:  
  2. + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache  
  3.  
  4. Sets a transition to apply to a view during an animation block. 

方法:

  1. exchangeSubviewAtIndex:withSubviewAtIndex:  
  2.     - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2  
  3.  
  4.     Exchanges the subviews at the specified indices.  
  5.     index1: The index of the first subview in the receiver.  
  6.     index2: The index of the second subview in the receiver. 

關(guān)于方法exchangeSubviewAtIndex:withSubviewAtIndex:實現(xiàn)的效果也可以用其他方式來實現(xiàn)。比如:

  1. UIViewController Controller  
  2.     UIView v1  
  3.     UIView v2  
  4. Controller.view = v1;//v1 front  
  5. Controller.view = v2;//v2 front 

當然,這只是實踐中應(yīng)用,但不一定這么用。用UIViewController實現(xiàn)不了動畫效果,至少現(xiàn)在我不知道UIViewController本身可否實現(xiàn)動畫效果。

關(guān)于另外一種方式來實現(xiàn)動畫效果Core Animation Transition,作用于層,而非視圖,看如下代碼:

  1. - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{      
  2. CATransition *animation = [CATransition animation];      
  3. [animation setDelegate:self];      
  4. [animation setDuration:1.0f];      
  5. [animation setTimingFunction:UIViewAnimationCurveEaseInOut];     
  6. [animation setType: kCATransitionPush];      
  7. [animation setSubtype: kCATransitionFromLeft];         
  8. [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];      
  9. [[[self superview] layer] addAnimation:animation forKey:@"transitionViewAnimation"];    
  10.  } 

#p#

CATransition類此類針對層執(zhí)行轉(zhuǎn)換動畫繼承CAAnimation : NSObject屬性:

  1. delegate:  
  2. @property(retain) id delegate  
  3.  
  4.     Specifies the receiver’s delegate object.  
  5.  
  6. duration:  
  7. @property CFTimeInterval duration  
  8.  
  9.     Specifies the basic duration of the animation, in seconds. (required)  
  10.  
  11. timingFunction:  
  12. @property(retain) CAMediaTimingFunction *timingFunction  
  13.  
  14.     An optional timing function defining the pacing of the animation.  
  15.  
  16. subtype  
  17. @property(copy) NSString *subtype  
  18.     Specifies an optional subtype that indicates the direction for the predefined motion-based transitions.  
  19.  
  20. Discussion  
  21.     The possible values are shown in “Common Transition Subtypes”. The default is nil.  
  22.  
  23. type  
  24. @property(copy) NSString *type  
  25. Discussion  
  26.     The possible values are shown in “Common Transition Types”. The default is kCATransitionFade. 

Constants/常量

  1. Common Transition Types  
  2.     These constants specify the transition types that can be used with the type property.  
  3.     NSString * const kCATransitionFade;  
  4.     NSString * const kCATransitionMoveIn;  
  5.     NSString * const kCATransitionPush;  
  6.     NSString * const kCATransitionReveal;  
  7.     kCATransitionFade  
  8.         The layer’s content fades as it becomes visible or hidden.  
  9.     kCATransitionMoveIn  
  10.         The layer’s content slides into place over any existing content. The “Common Transition Subtypes” are used with this transition.  
  11.     kCATransitionPush  
  12.         The layer’s content pushes any existing content as it slides into place. The “Common Transition Subtypes” are used with this transition.  
  13.     kCATransitionReveal  
  14.         The layer’s content is revealed gradually in the direction specified by the transition subtype. 
  15. The “Common Transition Subtypes” are used with this transition.  
  16. Common Transition Subtypes  
  17.     These constants specify the direction of motion-based transitions. They are used with the subtype property.  
  18.     NSString * const kCATransitionFromRight;  
  19.     NSString * const kCATransitionFromLeft;  
  20.     NSString * const kCATransitionFromTop;  
  21.     NSString * const kCATransitionFromBottom;  
  22.     kCATransitionFromRight  
  23.         The transition begins at the right side of the layer.  
  24.     kCATransitionFromLeft  
  25.         The transition begins at the left side of the layer.  
  26.     kCATransitionFromTop  
  27.         The transition begins at the top of the layer.  
  28.     kCATransitionFromBottom  
  29.         The transition begins at the bottom of the layer.  
  30.     Declared in CAAnimation.h. 

在后續(xù)例子中也有此CATransition類的學習,具體方法實際中去參考CALayer類。

方法:

  1. addAnimation:forKey:  
  2.     - (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key  
  3.     Add an animation object to the receiver’s render tree for the specified key.  
  4.     anim: The animation to be added to the render tree.  
  5.     key: A string that specifies an identifier for the animation. 

在后續(xù)的滑動視圖中,使用CATransition實現(xiàn),關(guān)鍵在于生成一個控制層運動的對象,看代碼:

  1. - (CATransition *) getAnimation:(NSString *) direction{     
  2.  CATransition *animation = [CATransition animation];      
  3.  [animation setDelegate:self];     
  4.   [animation setType:kCATransitionPush];     
  5.    [animation setSubtype:direction];      
  6.    [animation setDuration:1.0f];      
  7.    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];  
  8. return animation;  

  1. [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

這句代碼和前面有些不一樣吧。

另外一個關(guān)鍵:定義一個滑動方向,在touchesBegan初始化,在touchesMoved獲取當前值,在touchesEnded中使用。多閱讀此代碼

小結(jié):Xcode學習之視圖轉(zhuǎn)換例子實踐的內(nèi)容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關(guān)推薦

2011-08-01 10:01:12

Xcode UIView 動畫

2011-07-20 14:31:56

XCode User Scrip 腳本

2011-08-01 15:57:58

2011-08-01 16:50:28

Xcode 動態(tài) View

2011-08-01 17:01:02

Xcode WindowBase View

2011-08-01 17:50:28

Xcode

2011-08-10 14:00:22

XcodeUIWebView視頻

2011-08-11 16:31:08

XCode

2011-08-18 10:17:21

Xcode4Xcode

2015-05-25 10:01:17

WatchKitAPP

2011-07-25 15:42:38

Xcode Vim

2011-08-08 17:05:02

XCode UserScript 腳本

2010-04-19 10:20:19

Oracle參數(shù)

2013-07-25 15:19:23

iOS開發(fā)學習Xcode打包framiOS開發(fā)

2011-08-01 09:26:51

Xcode Xcode 4 Instrument

2011-08-19 15:16:41

XCodeUserScripts腳本

2011-08-01 17:31:25

Xcode開發(fā) Cocoa

2011-07-29 18:52:59

Xcode安裝 MacOS Windows

2014-03-12 09:52:17

XcodeCode Snippe

2011-07-19 15:55:09

Xcode Interface Builder
點贊
收藏

51CTO技術(shù)棧公眾號