我有一个 View ,我想像这里的插图一样翻转。
我目前的解决方案:
[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:]
会为透视图或其他东西设置动画,所以动画会缩小 View 并做一些我无法解释的奇怪事情.所以我现在自己制作动画,每次都改变角度。
最佳答案
你的意思是这样的吗:
[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);
}];
现在尝试一下。
关于ios - UIView 的动画透视以向上/远离底部翻转一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23292135/