在动画中的SubView幻灯片,iphone [英] SubView slide in animation, iphone
问题描述
我有一个包含两个UIButtons的UIview。
I have a UIview Containing two UIButtons.
-(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];
}
我希望在调用以下方法时动画显示UIview的幻灯片。
I want to animate slide in of UIview when following method is called.
-(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];
}];
}
提前获得任何帮助。
推荐答案
您需要添加一个帧值,该值是您希望动画开始的地方(屏幕外?)然后更改动画中的帧值块。框架将在持续时间内发生变化,从而导致运动的出现。该视图必须已经是一个子视图 - 我不相信添加子视图是你可以动画的东西,这没有任何意义。
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
}];
}
这篇关于在动画中的SubView幻灯片,iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!