Ios 两个相似的动画表现不同
我通过故事板配置了UIView。此视图(Ios 两个相似的动画表现不同,ios,animation,views,coordinates,Ios,Animation,Views,Coordinates,我通过故事板配置了UIView。此视图(self.view)有一个子视图,一个按钮(self.cartButton)。在后面的代码中,我向该视图添加了子视图: [self.view addSubview:self.cart.view]; 我有以下方法: - (void)openCart { [UIView animateWithDuration:2 animations:^{ self.cartButton.frame = CGRectMake(0.0f, 0.0f,
self.view
)有一个子视图,一个按钮(self.cartButton
)。在后面的代码中,我向该视图添加了子视图
:
[self.view addSubview:self.cart.view];
我有以下方法:
- (void)openCart
{
[UIView animateWithDuration:2 animations:^{
self.cartButton.frame = CGRectMake(0.0f, 0.0f, self.cartButton.frame.size.width, self.cartButton.frame.size.height);
self.cart.view.frame = CGRectMake(0.0f, 0.0f, self.cart.view.frame.size.width, self.cart.view.frame.size.height);
}];
}
我认为它应该将两个对象都移动到屏幕的顶部,但真正发生的是cartButton动画移动到最底部的位置,而cart视图移动到顶部。为什么会发生这种情况?我把坐标系搞砸了吗
更新:如果我注释掉动画中的第二行(设置购物车视图的动画),cartButton
会飞到顶部
更新2:它与我的cartView
有关。它是一个通用视图(在情节提要中创建)。例如,当我尝试使用导航控制器
制作相同的动画时,它会起作用
更新3:如果我的购物车视图没有子视图,它可以正常工作。如果其中有任何内容(按钮、导航栏、、任何内容……),则它不起作用。如何在视图中添加按钮?使用界面设计器。是否启用了自动布局?是的,我启用了。按钮如下所示: