我正在我的一个视图上添加一个子视图,并为其设置动画,使其从屏幕底部开始,并通过使用animateWithDuration结束于屏幕顶部 . 并且一切正常,除了在完成 animateWithDuration 之后,顶部的视图没有用户交互,并且下面的视图仍然具有用户交互 . 如果我删除了 animateWithDuration ,并且只是在它的正常位置启动子视图,那么用户交互也会起到我期望的作用,这就是为什么我认为 animateWithDuration 是问题所在 .
Here's my code:
UIViewController *viewController = [[CCouponDetailViewController alloc] init];
[[viewController view] setBounds:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height * -1), viewController.view.bounds.size.width, viewController.view.bounds.size.height)];
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];
CGRect newFrame = viewController.view.frame;
newFrame.origin.x = 0;
newFrame.origin.y = ([UIScreen mainScreen].bounds.size.height * -1);
[UIView animateWithDuration:1.0
animations:^{
viewController.view.frame = newFrame;
}
completion:^(BOOL finished){
[viewController didMoveToParentViewController:self];
}
];
我有另一个问题(不是很重要,只是好奇)是在newFrame中我将y设置为与我最初设置边界时相同的东西,但它会移动 . 我原以为newFrame要求y值为“0”但是当我这样做时没有发生任何事情 . 只是想知道为什么会这样 .
1 回答
我实际上会倒退这个......
"Another question I have (Not really important just curious) is that in newFrame I'm setting the y to the same thing as it is when I initially set the bounds, but yet it moves. I would have expected newFrame to require a y value of " 0 " but when I did that nothing happened. Just wondering why that is."
对于您来说,这实际上是一个非常重要的问题,因为它与您的代码无法正常工作有很大关系 . 你误解了一些非常重要的概念 .
首先,
bounds
的bounds
完全决定了它自己的位置 .frame
确定UIView
's position within its superview. In your code, you'最初设置视图的bounds
,而不是frame
-基本上,你最终会得到一个带有0x0帧的
CCouponDetailViewController
视图,但是由于你没有指定你希望你的UIView
剪辑其子视图,你的CCouponDetailViewController
视图的部分实际上并不在他们的视图之上,而是可见的并且悬挂在UIView
's bounds. The reason they aren' t可选择是因为它们实际上并不在UIView
内 .所以要解决这个问题,设置你的
UIView
的初始帧而不是设置一个边界(我正在尝试做的事情 . 顺便说一句,我没有尝试做)...:其次,您正在错误地设置新框架 . 你不能这样设置CGRect:
相反,使用
CGRectMake
设置它(再次,我编辑了y值,以便视图最终位于屏幕顶部,就像您尝试做的那样):