简体   繁体   English

将视图扩展到超级视图的底部

[英]Extend view to bottom of superview

I want to animate a view inside ViewController, somewhat like the notification center as seen on the iPhone. 我想为ViewController中的视图设置动画,有点像在iPhone上看到的通知中心。

How does one extend the subview using the x,y and/or the height values to do this? 如何使用x,y和/或height值扩展子视图? Because I would like it to be compatible with both the 3.5 inch screens and the 4 inch screens, so it would be better not to use specific values. 因为我希望它与3.5英寸屏幕和4英寸屏幕都兼容,所以最好不要使用特定的值。

I just tested this out in my own project and confirmed that it works on varying screen sizes. 我刚刚在自己的项目中对此进行了测试,并确认它可以在各种屏幕尺寸下使用。

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);
}];

To implement this, simply replace slidingview with the view you want to slide down. 要实现此目的,只需将slidingview替换为要向下滑动的视图即可。 You would, however, have to declare your own view using the frame I provided. 但是,您将必须使用我提供的框架声明自己的视图。

How about something like this? 这样的事情怎么样?

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;
}];

You may need to use delay version of animateWithDuration... to make animation in effect. 您可能需要使用animateWithDuration... delay版本才能使动画生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM