子视图滑块,iphone
问题描述:
我有一个UIView含有两个UIButtons。子视图滑块,iphone
-(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中滑动滑动。
-(void) showAnimation
我试图按照以下方式做,但我看不到动画。我该怎么做?
-(void) showAnimation{
[UIView animateWithDuration:10.0 animations:^{
[self.view addSubview:geopointView];
}];
}
Thannks提前的任何帮助。
答
你需要用帧值也就是你希望动画从开始添加子视图(关屏?)然后改变你的动画块内的帧值。框架会在整个持续时间内发生变化,导致运动的出现。该视图必须已经是一个子视图 - 我不认为添加子视图是可以进行动画制作的,这是没有意义的。
-(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
}];
}
非常感谢..它完全按照要求工作.. – alekhine
什么是输出?你能告诉我一些...我需要实现它 – magid