iOS-3D旋转View

需求:拖动ScrollView 旋转另一个View。

设置锚点 '_imgView.layer.anchorPoint' 告诉从哪里旋转 设置初始状态_imgView.layer.transform = CATransform3DMakeRotation(-M_PI_2, 1, 0, 0); 设置scrollview代理 根据拖动的contentOffset 设置旋转的大小进度!

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20)]; scrollView.delegate = self; scrollView.backgroundColor = [UIColor clearColor]; [self.view addSubview:scrollView]; scrollView.contentSize =CGSizeMake(self.view.frame.size.width, 1000);

_imgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - headHeight / 2, 0, headHeight,headHeight)];

_imgView.image = [UIImage imageNamed:@"1"];

[self.view addSubview:self.imgView];

_imgView.layer.anchorPoint = CGPointMake(0.5, 0);

here_imgView.layer.transform = CATransform3DMakeRotation(-M_PI_2, 1, 0, 0);

-(void)scrollViewDidScroll:(UIScrollView )scrollView{

 NSLog(@"scrollview offset;%f",scrollView.contentOffset.y); 

CGFloat offsetX = scrollView.contentOffset.y; 

if (offsetX > -headHeight && offsetX < 0) { CGFloat angle = -M_PI_2 offsetX / headHeight;

 _imgView.layer.transform = CATransform3DRotate(CATransform3DMakeRotation(-M_PI_2, 1, 0, 0), angle, 1, 0, 0); }

 } 

 代码链接:http://code.cocoachina.com/view/136086

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容