成人免费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動畫

2015-07-27 10:27:32

IOS基礎知識核心動畫

2011-05-11 10:28:03

2011-07-26 15:56:53

iPhone 游戲 啟動畫面

2011-06-24 16:09:24

Qt 動畫 狀態機

2011-07-18 16:57:36

Core Animation 動畫

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

2009-07-28 15:08:50

MVC三層架構實例

2011-07-22 16:47:53

iOS 通知 xcode

2011-07-26 11:08:23

iOS 錄像 錄音

2009-10-29 17:17:01

接入層技術
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 91免费视频| 久久国产精品免费视频 | 成人在线h | 91久久久久久久久久久 | www.日韩系列 | 欧美日韩在线成人 | 国产精品一区二区av | 欧美a∨ | 国产午夜精品一区二区三区嫩草 | 久久国产精品久久久久 | 国产成都精品91一区二区三 | 久久骚 | 国产在线观看av | 亚洲第一成人影院 | 精品视频免费在线 | 久久综合影院 | 一区二区三区日本 | 午夜视频一区 | 韩三级在线观看 | 99re在线视频 | 特级a欧美做爰片毛片 | 国产欧美一区二区三区久久人妖 | 精品国产欧美一区二区三区不卡 | 欧美一区二区三区 | 天天影视色综合 | 日韩av成人在线观看 | 欧美成人一区二免费视频软件 | 在线观看亚洲一区二区 | 欧美精品在线一区二区三区 | 中文字幕免费在线 | 欧美色综合一区二区三区 | 色吧综合 | 中文字幕一区在线观看视频 | 亚洲精品一区二区三区中文字幕 | 看片91| 国产在线视频三区 | 黄色毛片一级 | 日韩一区二区三区精品 | 懂色中文一区二区三区在线视频 | 亚洲欧美激情网 | 日韩欧美成人精品 |