2012-10-07 96 views
0

我想在ViewController中爲視圖設置動畫,就像在iPhone上看到的通知中心一樣。將視圖擴展到超級視圖的底部

如何使用x,y和/或高度值擴展子視圖來完成此操作?因爲我希望它可以兼容3.5英寸的屏幕和4英寸的屏幕,所以最好不要使用特定的值。

回答

0

我剛剛在我自己的項目中測試了這一點,並確認它適用於不同的屏幕尺寸。

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。但是,您必須使用我提供的框架聲明您自己的觀點。

0

這樣的事情呢?

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

您可能需要使用delay版本的animateWithDuration...使動畫效果。