成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Xcode學習之視圖轉換例子實踐

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

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

翻轉(類似翻書)視圖效果,兩種實現方式

滑動視圖效果

分別看各自實現的重點:

翻轉視圖效果例子

在官方上,提供

  1. UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight 

方法,來實現視圖向左或向右翻轉。

在UIView動畫塊中使用轉換,需要2個工作:

1、必須將轉換作為塊參數添加

2、應該在塊內部重新安排視圖順序。

效果代碼如下:

  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事件上的,也是符合翻轉邏輯

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

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

第二處表示子視圖集合中,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. 

關于方法exchangeSubviewAtIndex:withSubviewAtIndex:實現的效果也可以用其他方式來實現。比如:

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

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

關于另外一種方式來實現動畫效果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類此類針對層執行轉換動畫繼承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. 

在后續例子中也有此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. 

在后續的滑動視圖中,使用CATransition實現,關鍵在于生成一個控制層運動的對象,看代碼:

  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]]; 

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

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

小結:Xcode學習之視圖轉換例子實踐的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關推薦

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 動態 View

2011-08-01 17:01:02

Xcode WindowBase View

2011-08-01 17:50:28

Xcode

2011-08-11 16:31:08

XCode

2011-08-10 14:00:22

XcodeUIWebView視頻

2011-08-18 10:17:21

Xcode4Xcode

2011-07-25 15:42:38

Xcode Vim

2015-05-25 10:01:17

WatchKitAPP

2013-07-25 15:19:23

iOS開發學習Xcode打包framiOS開發

2011-08-08 17:05:02

XCode UserScript 腳本

2010-04-19 10:20:19

Oracle參數

2011-08-01 17:31:25

Xcode開發 Cocoa

2011-08-19 15:16:41

XCodeUserScripts腳本

2011-08-01 09:26:51

Xcode Xcode 4 Instrument

2014-03-12 09:52:17

XcodeCode Snippe

2011-07-29 18:52:59

Xcode安裝 MacOS Windows

2011-07-19 15:55:09

Xcode Interface Builder
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 在线视频91 | av影音资源 | 国产一区二区在线免费播放 | 播放一级毛片 | 日日夜夜天天 | 看a级黄色毛片 | 中文字字幕一区二区三区四区五区 | 久久久久久久久久久91 | 日韩电影一区 | 在线视频91 | 中文字幕欧美一区 | 日韩欧美三级在线 | 亚洲一二三区精品 | 欧美精品综合在线 | 欧美日韩一区二区三区在线观看 | 亚洲一区二区精品视频在线观看 | 欧美一级电影免费观看 | 久久6视频 | 亚洲精品www.| 免费成人在线网站 | 欧美黄色片在线观看 | www4虎 | 亚洲视频一区在线 | 欧美日韩精品亚洲 | 精品国产乱码久久久久久影片 | 不卡的av一区 | 色就是色欧美 | 欧美久久一区二区 | 免费视频二区 | 国产精品免费一区二区三区四区 | 国产不卡在线观看 | 一级欧美 | 亚洲成人av | 7777精品伊人久久精品影视 | 中文字幕高清av | 成人午夜精品 | 激情国产在线 | 希岛爱理在线 | 久久偷人 | 一区二区久久精品 | 亚欧精品一区 |