将视图扩展到superview的底部

时间:2012-10-07 20:16:00

标签: iphone objective-c ios xcode

我想在ViewController中设置一个视图动画,有点像iPhone上看到的通知中心。

如何使用x,y和/或高度值扩展子视图来执行此操作?因为我希望它兼容3.5英寸屏幕和4英寸屏幕,所以最好不要使用特定值。

2 个答案:

答案 0 :(得分: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替换为您要向下滑动的视图即可。但是,您必须使用我提供的框架声明您自己的视图。

答案 1 :(得分: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...才能使动画生效。