![](/img/trans.png)
[英]How to make the view of a UIViewController to stick to the bottom of it's superview?
[英]Extend view to bottom of superview
我想为ViewController中的视图设置动画,有点像在iPhone上看到的通知中心。
如何使用x,y和/或height值扩展子视图? 因为我希望它与3.5英寸屏幕和4英寸屏幕都兼容,所以最好不要使用特定的值。
我刚刚在自己的项目中对此进行了测试,并确认它可以在各种屏幕尺寸下使用。
UIView *slidingview = [[UIView alloc] initWithFrame:CGRectOffset(self.view.frame, 0, -self.view.frame.size.height)];
slidingview.backgroundColor = [UIColor whiteColor];
[self.view addSubview:slidingview];
[UIView animateWithDuration:1 animations:^{
slidingview.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
}];
要实现此目的,只需将slidingview
替换为要向下滑动的视图即可。 但是,您将必须使用我提供的框架声明自己的视图。
这样的事情怎么样?
CGRect currentFrame = self.view.bounds;
UIView * slidingView = [UIView alloc] initWithFrame:(CGRect){currentFrame.origin, currentFrame.size.width, 0};
[self.view addSubview:slidingView];
[UIView animateWithDuration:0.5f animations:^{
slidingView.frame = currentFrame;
}];
您可能需要使用animateWithDuration...
delay
版本才能使动画生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.