沿 X 轴(水平轴)旋转 UIView
我想将 UIView 在其水平轴上旋转 360 度,然后刷新视图中的内容。我一直在寻找这方面的解决方案。在这里和那里发现了一对。这就是我得出的结果。
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
} completion:^(BOOL finished){
NSLog(@"Finished first pi");
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
} completion:^(BOOL finished) {
NSLog(@"Finished second pi");
}];
}];
这会翻转视图,但仅翻转 180 度。我希望它再翻转一次,以便我可以正常看到视图。
我的两个 NSLog 都一个接一个地显示。我确信我在这里遗漏了一些东西。任何帮助都会有帮助..
谢谢
I wanted to rotate a UIView on its horizontal axis for 360 degrees and then refresh the content in the view. I was looking out for solutions on this. Found a couple here n there. This is what I came out with.
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
} completion:^(BOOL finished){
NSLog(@"Finished first pi");
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionNone animations:^{
self.tableView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
} completion:^(BOOL finished) {
NSLog(@"Finished second pi");
}];
}];
This flips the view but only by 180 degrees. I want it to flip one more time so that I can see the view normally..
Both my NSLogs are displayed one after the other. I am sure I am missing something here. ANy help would be helpful..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在完成块中尝试将新转换与当前转换连接起来。
In your completion block try concatenating the new transform with the current transform.
您应该检查这个答案 如何使CATransform3dMakeRotation以另一种方式旋转?并链接在一起
我认为你的问题与:“当你直接使用变换时,核心动画会将变换从当前值插值到指定的变换。它将找到到达的最短路径该变换,这将限制动画方向。如果您尝试对同一变换属性进行两次动画处理,则第二个值将简单地覆盖第一个值,而不是将两个变换组合在一起。”
You should check this answer How to make a CATransform3dMakeRotation rotate the other way? And chain together
I think that your problem is related with: "When you are working with a transform directly, Core Animation will interpolate the transform from the current value to the specified transform. It will find the shortest path to get to that transform, which will restrict the animation direction. If you try to animate the same transform property twice, the second value will simply override the first, not combine the two transforms together."
使用这个:-
use this:-
您只需在完成块内将代码从 1.0 更改为 0.0 就可以了。
You just have to change your code from 1.0 to 0.0 inside completion block and woohoo all done.
您还可以使用
.Repeat
和.Autoreverse
动画选项 + 设置动画的重复次数来实现此目的。下面是 Swift 中的一个例子:You can also approach this using the
.Repeat
and.Autoreverse
animation options + setting animation's repeat count. Here's an example in Swift: