0

我想为 ViewController 中的视图设置动画,有点像 iPhone 上的通知中心。

如何使用 x,y 和/或高度值扩展子视图来做到这一点?因为我希望它同时兼容 3.5 英寸和 4 英寸的屏幕,所以最好不要使用特定的值。

4

2 回答 2

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为要向下滑动的视图。但是,您必须使用我提供的框架声明您自己的视图。

于 2012-10-07T20:25:57.077 回答
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...才能使动画生效。

于 2012-10-07T21:40:26.757 回答