![](/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.