子视图滑动animation,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 

我试图按照下面的方式去做,但是我看不到animation。 我该怎么做?

 -(void) showAnimation{ [UIView animateWithDuration:10.0 animations:^{ [self.view addSubview:geopointView]; }]; } 

Thannks提前任何帮助。

你需要添加一个框架值的子视图,你想从哪里开始animation(离屏?),然后改变你的animation块内的框架值。 画面会随着时间而改变,引起移动的外观。 该视图必须已经是一个子视图 – 我不相信添加子视图是可以animation的东西,这是没有意义的。

 -(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 }]; }