我正在尝试在这里做一些非常基本的事情。我正在使用基于 block 的 UIView 动画将当前离开屏幕的 subview 带到当前 View 的中心。显然 sp.view.frame = self.view.center
行是这里的问题。最后,我该如何做我想做的事?
[UIView animateWithDuration:1 delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
sp.view.frame = self.view.center;
}
谢谢!
最佳答案
首先,sp.view.frame
返回一个 CGRect
而 self.view.center
返回一个 CGPoint
.两者不是同一类型,因此不能将一个设置为另一个。假设您希望将 sp.view
的中心设置为 self.view
的中心,您可以通过以下两种方式之一实现:
sp.view.center = self.view.center;
或
[sp.view setCenter:self.view.center];
关于ios - 如何使用 view.frame 和 view.center 将两个 View 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7394288/