我有一个观点,我想在这里翻看这个例子。
我目前的解决方案:
[UIView animateWithDuration:duration
animations:^{
[someView.layer setAffineTransform:CGAffineTransformMakeScale(1, 0)];
}];
此解决方案的问题在于顶边向下移动,而底边向上移动。我希望顶边保持不变,底边向上/向外移动,如图所示。
编辑:就像那些猫门,哈哈。你可以用顶部的铰链将光盘/方形表面推离你。EDIT2:解决方案。
CGFloat someViewHeight = self.someView.frame.size.height;
CATransform3D baseTransform = CATransform3DIdentity;
baseTransform.m34 = - 1.0 / 200.0;
self.someView.layer.zPosition = self.view.frame.size.height * 0.5;
self.someView.layer.transform = baseTransform;
CATransform3D rotation = CATransform3DMakeRotation(- M_PI_2, 1.0, 0.0, 0.0);
CATransform3D firstTranslation = CATransform3DMakeTranslation(0.0, someViewHeight * 0.5, 0.0);
CATransform3D secondTranslation = CATransform3DMakeTranslation(0.0, - someViewHeight * 0.5, 0.0);
self.someView.layer.transform = CATransform3DConcat(CATransform3DConcat(firstTranslation, CATransform3DConcat(rotation, secondTranslation)), baseTransform);
花了一段时间,直到我发现[UIView animateWithDuration:]
会为视角或其他东西设置动画,所以动画会缩小视图并做一些我无法解释的奇怪的东西。所以我现在为自己设置动画,只是改变每次的角度。
答案 0 :(得分:3)
你的意思是这样的:
[UIView animateWithDuration:3.0 animations:^{
[someView.layer setAffineTransform:
CGAffineTransformConcat(CGAffineTransformMakeScale(1.0f, .0001f), CGAffineTransformMakeTranslation(.0f, someView.frame.size.height*-.5f))];
}];
这只是解决您所描述的问题,要在图片上显示结果,您需要进行3D转换。
要进行3D转换,事情变得非常棘手:
CGFloat viewHeight = someView.frame.size.height; //needed later as this value will change because of transformation applied
CATransform3D baseTransform = CATransform3DMakeTranslation(.0f, .0f, viewHeight*.5f); //put it towards user for rotation radius
baseTransform.m34 = -1.0/200.0; //this will make the perspective effect
someView.layer.zPosition = view.frame.size.height*.5f; //needed so the view isn't clipped
someView.layer.transform = baseTransform; //set starting transform (no visual effect here)
[UIView animateWithDuration:6.6 animations:^{
someView.layer.transform = CATransform3DConcat(CATransform3DConcat(CATransform3DMakeRotation(-M_PI_2, 1.0f, .0f, .0f), CATransform3DMakeTranslation(.0f, viewHeight*.5f, .0f)) , baseTransform);
//or to stay at the same center simply:
//someView.layer.transform = CATransform3DConcat(CATransform3DMakeRotation(-M_PI_2, 1.0f, .0f, .0f) , baseTransform);
}];
现在玩一下吧。