子视图滑入动画,iPhone

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

提前感谢任何帮助。

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

什么是输出?你能给我展示一些吗?我需要实现它。 - Majid Bashir

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接