博客> iOS-3D旋转View
iOS-3D旋转View
2018-11-13 09:56 评论:0 阅读:4189 郭鹏飞
transform CATransform3DRotate

 iuo.gif 需求:拖动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

收藏
2
sina weixin mail 回到顶部