簡體   English   中英

將視圖擴展到超級視圖的底部

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM