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

IOS實例 CALayer層動畫點擊

移動開發 iOS
本文介紹的IOS實例 CALayer層動畫點擊,CALayer在運動過程中,需要點擊CALayer,同時能夠監控到點擊的對象,來看具體內容。

IOS實例 CALayer動畫點擊是本文要介紹的內容,利用CALayer可以實現復雜的動畫效果,同時CALayer在運動過程中,需要點擊CALayer,同時能夠監控到點擊的對象。下面是實現的效果和過程。如圖所示:

IOS實例 CALayer層動畫點擊

實現過程:

  1. #import "AnimView.h"   
  2. @implementation AnimView  
  3.  
  4. - (id)initWithFrame:(CGRect)frame {   
  5.       
  6.     self = [super initWithFrame:frame];   
  7.     if (self) {   
  8.         [self setBackgroundColor:[UIColor clearColor]];   
  9.         UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchesPoint:)];   
  10.         [self addGestureRecognizer:tapGesture];   
  11.         [tapGesture release];   
  12.     }   
  13.     return self;   
  14. }   
  15. -(void) drawRect:(CGRect)rect   
  16. {   
  17.     [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(stratAnim:) userInfo:nil repeats: NO];   
  18. }   
  19. -(void)stratAnim:(id)sender   
  20. {   
  21.     //添加層   
  22.     layer2 = [CALayer layer];   
  23.     [layer2 setBackgroundColor:[[UIColor redColor] CGColor]];   
  24.     layer2.bounds = CGRectMake(0, 0, 60,40);//層設置為圖片大小   
  25.     layer2.position = CGPointMake(25,25);//層在view的位置   
  26.     [self.layer addSublayer:layer2];//將層加到當前View的默認layer下   
  27.       
  28.     [self startFlyStarAnimation];   
  29. }   
  30. -(void) startFlyStarAnimation   
  31. {      
  32.     //運動軌跡   
  33.     CGMutablePathRef thePath=CGPathCreateMutable();   
  34.     CGPathMoveToPoint(thePath,NULL,self.center.x,self.center.y);   
  35.     CGPathAddLineToPoint(thePath, NULL, self.center.x, self.center.y-45);   
  36.     CGPathAddLineToPoint(thePath, NULL, self.center.x, self.center.y+45);   
  37.     CGPathAddLineToPoint(thePath, NULL, self.center.x, self.center.y);   
  38.       
  39.     //添加動畫   
  40.     CAKeyframeAnimation * animation;   
  41.     animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];   
  42.     animation.path=thePath;   
  43.     animation.duration=3.0;   
  44.     animation.repeatCount=2;   
  45.     CFRelease(thePath);   
  46.     [animation setDelegate:self];   
  47.     //[self animationDidStop:animation finished:YES];   
  48.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];   
  49.     [layer2 addAnimation:animation forKey:kCATransition];   
  50. }   
  51. //動畫停止   
  52. -(void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag   
  53. {   
  54.     NSLog(@">>>>動畫停止了");   
  55. }   
  56. //touch事件   
  57. -(void)touchesPoint:(UITapGestureRecognizer *)gestureRecognizer   
  58. {   
  59.     CGPoint locationInView = [gestureRecognizer locationInView:self];   
  60.     //presentationLayer layer的動畫層   
  61.    CALayer *layer1=[[layer2 presentationLayer] hitTest:locationInView];   
  62.     if (layer1!=nil) {   
  63.         NSLog(@"點擊了運動的layer");   
  64.     }   
  65. }   
  66. - (void)dealloc {   
  67.     [super dealloc];   
  68. }   
  69. @end  

其中presentationLayer是CALayer動畫的位置層。

源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.presentlayer/

小結:IOS實例 CALayer動畫點擊的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

2011-07-22 18:20:04

IOS View 動畫

2015-03-24 09:37:50

SwiftiOSCALayer

2012-12-24 13:38:01

iOSUIView

2015-06-18 10:33:02

iOS粘性動畫

2009-06-29 14:21:00

無線網絡家庭組網

2011-07-03 10:05:52

Core Animat

2011-08-09 17:16:56

CoreAnimati動畫

2011-05-11 10:28:03

2015-07-27 10:27:32

IOS基礎知識核心動畫

2011-07-18 16:57:36

Core Animation 動畫

2011-07-26 15:56:53

iPhone 游戲 啟動畫面

2011-06-24 16:09:24

Qt 動畫 狀態機

2015-12-23 09:16:33

ios動畫渲染機制

2015-12-30 14:16:05

iOS動畫視圖渲染

2013-07-29 05:01:31

iOS開發iOS開發學習按鈕拖動和點擊

2010-09-14 14:42:24

FlashDIV CSS

2011-07-22 16:47:53

iOS 通知 xcode

2011-07-26 11:08:23

iOS 錄像 錄音

2009-07-28 15:08:50

MVC三層架構實例

2009-10-29 17:17:01

接入層技術
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 黄色成人免费在线观看 | 欧美日韩视频在线 | 狠狠爱综合网 | 日韩综合网 | 亚洲精品一区二区三区 | 国产精品欧美一区喷水 | 亚洲中午字幕 | 欧美一区二区三区在线播放 | 久久久久99| 久久久久国产 | 欧美成人激情 | 黄色视频a级毛片 | 欧美一区二区成人 | 国产日韩av一区二区 | 国产精品久久久久久久久久免费看 | 九九综合 | 亚洲一区高清 | 美女爽到呻吟久久久久 | 国产精品久久一区二区三区 | 亚洲高清免费观看 | 亚洲一区二区三区福利 | 久久久久亚洲精品中文字幕 | 男人的天堂在线视频 | 日日夜夜精品视频 | 亚洲综合色视频在线观看 | 国产精品久久一区二区三区 | 亚洲高清在线观看 | 羞羞视频在线观看 | 久久99精品久久久久久国产越南 | 久久国产精品免费一区二区三区 | 夜夜操av| 中文字幕在线免费观看 | 国产h在线| 国产一区| 91玖玖| 91精品国产91久久久久久密臀 | 欧美国产精品一区二区 | 在线看av的网址 | 天天久 | www.操com| 精品国产乱码久久久久久a丨 |