做一个绕Y轴旋转的动画时遇到问题
来源:互联网 发布:sqlalchemy sql 编辑:程序博客网 时间:2024/06/01 09:05
这是我做的一个Demo,红色方块与蓝色矩形的super view都是self.view,当红色方块做绕Y轴旋转动画时,只看到一半的红色方形在旋转。
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // image view _pmainPicture=[[UIImageView alloc]initWithFrame:CGRectMake(0, 100, [[UIScreen mainScreen] bounds].size.width, 190.0f)]; _pmainPicture.backgroundColor = [UIColor blueColor]; _pmainPicture.contentMode = UIViewContentModeScaleAspectFill; _pmainPicture.userInteractionEnabled = YES; [self.view addSubview:_pmainPicture]; //button _pButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_pButton setTitle: @"请点击" forState: UIControlStateNormal]; _pButton.frame = CGRectMake(_pSwitch.frame.origin.x, _pSwitch.frame.origin.y+100, 200, 44); _pButton.backgroundColor = [UIColor blueColor]; [_pButton setTitleColor: [UIColor redColor] forState: UIControlStateNormal]; [_pButton addTarget: self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; _pButton.accessibilityIdentifier = @"myButton"; [self.view addSubview: _pButton]; // 头像 _headImageView = [[UIImageView alloc] init]; _headImageView.frame = CGRectMake(0, 100, 100, 100); _headImageView.backgroundColor = [UIColor redColor]; [self.view addSubview:_headImageView];}
这是按钮点击方法
-(void) buttonAction:(UIButton*) button{ [self rotate360WithDuration:2.0 repeatCount:1]; _headImageView.backgroundColor = [UIColor redColor]; _headImageView.animationDuration = 2.0; _headImageView.animationRepeatCount = 1; [_headImageView startAnimating];}
这是绕Y轴旋转的动画
- (void)rotate360WithDuration:(CGFloat)aDuration repeatCount:(CGFloat)aRepeatCount{ CAKeyframeAnimation *theAnimation = [CAKeyframeAnimation animation]; theAnimation.values = [NSArray arrayWithObjects: [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0,1,0)], [NSValue valueWithCATransform3D:CATransform3DMakeRotation(3.13, 0,1,0)], [NSValue valueWithCATransform3D:CATransform3DMakeRotation(3.13, 0,1,0)], [NSValue valueWithCATransform3D:CATransform3DMakeRotation(6.26, 0,1,0)], nil]; theAnimation.cumulative = YES; theAnimation.duration = aDuration; theAnimation.repeatCount = aRepeatCount; theAnimation.removedOnCompletion = YES; [_headImageView.layer addAnimation:theAnimation forKey:@"transform"];}
运行这些代码就看到一个效果,红色方块旋转的时候,只看到一半在旋转,就好像蓝色矩形遮住了一样。
如果改成以下代码
// 头像 _headImageView = [[UIImageView alloc] init]; _headImageView.frame = CGRectMake(0, 0, 100, 100); _headImageView.backgroundColor = [UIColor redColor]; [_pmainPicture addSubview:_headImageView];
这样重新运行代码,红色方块绕着Y轴旋转,没有被蓝色矩形遮住了。
这两段代码的区别是,前者红色方块与蓝色矩形在同一个父窗口上(self.view),后者红色方块与蓝色矩形不在同一个父窗口。
UIView是iOS系统中界面元素的基础,所有的界面元素都继承自它。它本身完全是由CoreAnimation来实现的。它真正的绘图部分,是由一个叫CALayer(Core Animation Layer)的类来管理。UIView本身,更像是一个CALayer的管理器,访问它的跟绘图和跟坐标有关的属性,例如frame,bounds等等,实际上内部都是在访问它所包含的CALayer的相关属性。
前者红色方块与蓝色矩形同在同一layer层,所以红色方块做动画时,影响了蓝色矩形。
0 0
- 做一个绕Y轴旋转的动画时遇到问题
- 沿y轴的空间旋转动画!!
- 做MDB时遇到的一个问题
- 使用CATransition做动画时遇到的问题
- 《Android Y轴旋转动画Animation》
- 3D旋转动画(延Y轴旋转)
- css3旋转(绕Y轴)
- 属性动画的绕x轴旋转的问题
- 关于旋转动画只能画少一个pai 的问题
- 一个简单的旋转动画
- 一个对象绕某个轴旋转,朝向另一个对象(在旋转瞄准过程中只沿着y轴旋转)
- 利用MCGS做旋转动画的方法
- 《Android Y轴旋转动画Animation》 X轴 Y轴 Z轴
- opencv——图像的旋转(绕X轴、Y轴、原点旋转)
- 制作了一个cocos2d-x下沿y轴旋转任意角度的精灵对象
- 制作了一个cocos2d-x下沿y轴旋转任意角度的精灵对象
- android之绕Y轴旋转
- 做android的一个sdk遇到的问题
- macports安装问题总结
- Newtonsoft.Json(Json.Net)学习笔记
- 预装WIN8的电脑是GPT分区模式,无法安装WIN7
- XYZZY
- nginx 负载均衡
- 做一个绕Y轴旋转的动画时遇到问题
- Unity3D-Mecanim动画系统-IK
- HDU 5532 Almost Sorted Array
- JSTL标签提示:"items" does not support runtime expressions
- crypto前台AES加密,后台AES解密
- HDU2046骨牌铺方格
- POJ 2251 3维BFS
- 互联网系统架构的演进
- 贪心算法证明问题