SubView слайд в анимации, iphone
У меня есть UIview, содержащий два 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 при вызове метода.
-(void) showAnimation
Я попытался сделать это следующим образом, но я не вижу анимации. Как я могу это сделать?
-(void) showAnimation{
[UIView animateWithDuration:10.0 animations:^{
[self.view addSubview:geopointView];
}];
}
Thanks для любой помощи заранее.
Ответы
Ответ 1
Вам нужно добавить subview с фреймовым значением, из которого вы хотите начать анимацию (вне экрана?), а затем изменить значение фрейма внутри блока анимации. Рамка будет меняться в течение продолжительности, вызывая появление движения. Представление уже должно быть subview - я не верю, что добавление subview - это то, что вы можете оживить, это не имеет никакого смысла.
-(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
}];
}