- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有 UIView,我想通过旋转为其设置动画。我也想使用自动布局。我已经看到了很多 stackoverflow 常见问题,但我没有找到任何适用的解决方案。那么,让我们从我的界面和动画代码开始吧;我有一个带有图像的 UIView,必须旋转它。现在我有一个按钮,可以激活旋转。在屏幕截图中你可以看到红叉,这一定是旋转中心(现在它在图像上,但我想在旋转的 UIView 之外制作旋转中心,我知道这可以用 AnchorPoint 存档)。
这是我的旋转动画代码:
#define ROTATE_DURATION 3.0
- (IBAction)rotateArrow {
CGAffineTransform transform = self.hand.transform;
NSLog(@"layer possition before animation x: %f; y: %f",self.hand.layer.position.x,self.hand.layer.position.y);
[UIView animateWithDuration:ROTATE_DURATION/3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.hand.transform = CGAffineTransformRotate(transform, 2*M_PI/3) ;
[self.hand layoutIfNeeded];
NSLog(@"layer possition after animation 1 x: %f; y: %f",self.hand.layer.position.x,self.hand.layer.position.y);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:ROTATE_DURATION/3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.hand.transform = CGAffineTransformRotate(transform, -2*M_PI/3) ;
[self.hand layoutIfNeeded];
NSLog(@"layer possition after animation 2 x: %f; y: %f",self.hand.layer.position.x,self.hand.layer.position.y);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:ROTATE_DURATION/3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
self.hand.transform = CGAffineTransformRotate(transform, 0) ;
[self.hand layoutIfNeeded];
NSLog(@"layer possition after animation 3 x: %f; y: %f",self.hand.layer.position.x,self.hand.layer.position.y);
}
completion:^(BOOL finished) {
}];
}];
}];
}
所以,问题是什么:当旋转正在进行时,UIView 会更改它的 center
和 layer.position
属性,这就是我的 UIView 在动画时“跳跃”的原因。如果关闭自动布局,则动画没问题。我看了 WWDC 2012“Auto Layout by Example”,发现我会使用 [self.hand layoutIfNeeded];
一切都很好,但根本不是。动画变得更流畅了,但我看到了这个“跳跃”。所以,这是我的“输出”。
动画时,UIView 会像您在图像上看到的那样向右移动,然后回到正常位置。我该如何解决这个“跳跃”?
这是一个日志:
layer possition before animation x: 160.000000; y: 99.500000
layer possition after animation 1 x: 197.349030; y: 114.309601
layer possition after animation 2 x: 197.349030; y: 114.309601
layer possition after animation 3 x: 160.000000; y: 99.500000
谢谢。
最佳答案
当我布局我的 View 时,一切都开始正常工作。当您进行转换时,请务必记住,自动布局始终会根据您设置的约束计算您的 View 边界和框架。所以,在我的例子中,我只是在我的旋转 View 中添加了中心垂直和水平对齐、宽度和高度,所以自动布局机制知道我的 View 到底在什么时候。一切顺利。这是一个很好的自动布局教程:
http://www.raywenderlich.com/50319/beginning-auto-layout-tutorial-in-ios-7-part-1
关于ios - 自动布局违反平移旋转动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19917420/
出现以下错误: INSERT INTO GroupMembers VALUES ('Goldfrat', 'Simon Palm') * ERROR at line 1: ORA-02291: int
据称以下代码违反了 OO 指导原则。 public class Main { public static String NAME = "James"; public Main() {
我创建了一个名为 EvenementBean 的 EJB 2 进行测试。然后我就把它删除了。现在每当尝试部署我的 .ear 项目时,我都会收到以下错误: WARN [verifier] EJB
我正在开发的一个应用程序正在使用 Oracle 和 Hibernate 作为 ORM。当我尝试插入 PartyUserObject 时,我不断收到以下错误: could not insert: [Pe
我已经实现了一些代码行: if(condition){ Class a = new Class(); method(a.b(), a.c()); }else{ method(null, n
这个问题在这里已经有了答案: Static analysis of noexcept "violations" in C++ (2 个答案) 关闭 4 年前。 我大量使用 noexcept,不幸的是
我有一个 MVVM 应用程序,在我的几个 VM 中,我使用 CollectionViewSource.GetDefaultView(datasource) 来初始化我的 ICollectionView
当我尝试运行我的网站时,它显示 500 internal server error : Internal Server Error The server encountered an internal
运行生存分析,假设变量的 p 值具有统计显着性 - 假设与结果呈正相关。但是,根据 Schoenfeld 残差,违反了比例风险 (PH) 假设。 在纠正 PH 违规后,以下哪种情况可能发生? p 值可
我知道以下是一个主观问题,但您的指导方针确实有助于我追求干净、可测试的代码。 请考虑以下示例,我认为它违反了一系列设计原则。 public class OfferEligibilityCheckerS
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭10 年前。 Improv
当我尝试将 Paho MQTT javacrript 与 Mosquito MQTT websockets 一起使用时,只要我用来服务页面的 Web 服务器和 Mosquito 位于同一服务器(同一来
我在通过 hibernate 映射 oracle 时遇到问题 我有这些类(class) Stock.java package com.mc.stock; import java.uti
在我的项目中,我试图解决 Sonar 违规问题,我坚持使用这个,我有以下代码 不允许使用以下属性:语言 谁能告诉我如何解决这个 Sonar 违规问题?我可以简单地删除这种“语言”吗属性还是我应该输
我正在尝试记录唯一标识符,所以我无法承受重复记录我的 ID 当我尝试更新名为 Clients 的 SQL Server 表时,我收到类似这样的错误。 Violation of PRIMARY KEY
我正在尝试实现一个解决方案,以在给定的整数列表中找到第 k 个最大的元素,其中重复项具有 O(N*log(N)) Big-O 表示法的平均时间复杂度,其中 N 是列表中元素的数量。 根据我的理解,合并
如果 tuple_size 模板是一个完整的类型,结构化绑定(bind)特性表示它会像分解一样与元组一起使用。当 std::tuple_size 在程序的某一点是给定类型的完整类型而在另一点不完整时会
我们的应用目前已从 google play 中删除,因为它具有 SMS 权限。我们已经删除了权限并上传了一个新的 apk,但项目的状态仍然是删除。我们是否必须等待他们审核,或者是否需要任何其他必要的步
*i 和 u.i 如何在此代码中打印不同的数字,即使 i 被定义为 int *i = &u.i;?我只能假设我在这里触发了 UB,但我看不出具体情况。 ( 如果我选择“C”作为语言,ideone de
您好,我正在 Oracle SQL dev 中开发一个数据库,它试图从另一个表访问外键。我目前正在处理使用以下 CREATE 语句创建的 ItemOrdered 表 CREATE TABLE Item
我是一名优秀的程序员,十分优秀!