ios 动画中的子视图幻灯片,iphone
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7343915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SubView slide in animation, iphone
提问by alekhine
I have a UIview Containing two UIButtons.
我有一个包含两个 UIButton 的 UIview。
-(void)ViewDidLoad
{
geopointView = [[UIView alloc] initWithFrame:CGRectMake(0, 350, 120, 80)];
geopointView.backgroundColor = [UIColor greenColor];
UIButton *showGeoPointButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
showGeoPointButton.frame = CGRectMake(0, 0, 120, 40);
showGeoPointButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
[showGeoPointButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[showGeoPointButton addTarget:self action:@selector(showPlaces:) forControlEvents:UIControlEventTouchUpInside];
UIButton *SaveButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]
SaveButton.frame = CGRectMake(0, 40, 120, 40);
SaveButton.titleLabel.font = [UIFont systemFontOfSize: 15.0];
[SaveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[SaveButton addTarget:self action:@selector(savePlacePopUp) forControlEvents:UIControlEventTouchUpInside];
[geopointView addSubview:showGeoPointButton];
[geopointView addSubview:SaveButton];
}
I want to animate slide in of UIview when following method is called.
我想在调用以下方法时为 UIview 的滑入设置动画。
-(void) showAnimation
I tried to do it by following way but I can see no animation. How can I do it?
我试图通过以下方式做到这一点,但我看不到动画。我该怎么做?
-(void) showAnimation{
[UIView animateWithDuration:10.0 animations:^{
[self.view addSubview:geopointView];
}];
}
Thannks for any help in advance.
提前感谢您的任何帮助。
回答by Adam Eberbach
You need to add the subview with a frame value that is where you want the animation to begin from (off-screen?) then change the frame value inside your animation block. The frame will change over the duration, causing the appearance of movement. The view must already be a subview - I don't believe adding a subview is something you can animate, it makes no sense.
您需要添加具有帧值的子视图,该帧值是您希望动画开始的位置(屏幕外?),然后更改动画块内的帧值。帧会随着时间的推移而改变,从而导致运动的出现。该视图必须已经是一个子视图 - 我不相信添加子视图是您可以制作动画的东西,这是没有意义的。
-(void)showAnimation {
[self.view addSubview:geopointView]
geopointView.frame = // somewhere offscreen, in the direction you want it to appear from
[UIView animateWithDuration:10.0
animations:^{
geopointView.frame = // its final location
}];
}