15

我有一个包含两个 UIButtons 的 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];
}

当调用以下方法时,我想为 UIview 的幻灯片制作动画。

-(void) showAnimation

我试图通过以下方式做到这一点,但我看不到动画。我该怎么做?

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

感谢您提前提供任何帮助。

4

1 回答 1

60

您需要添加具有帧值的子视图,该帧值是您希望动画开始的位置(屏幕外?),然后更改动画块内的帧值。帧将在持续时间内发生变化,从而产生运动的外观。该视图必须已经是一个子视图 - 我不认为添加子视图是您可以制作动画的东西,这没有任何意义。

-(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
                     }];
}
于 2011-09-08T06:23:16.730 回答