添加子视图动画 [英] addSubview animation

查看:30
本文介绍了添加子视图动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示不同数据的主 UIView.然后我放了一个按钮,它显示这样的子视图:

I have main UIView where I display different data. Then I put a button, which displays subview like this:

- (IBAction) buttonClicked:(id)sender
{
    UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(25,25,50,20)];
    UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(25,25,50,25)];
    newLabel.text = @"some text";
    [newView addSubview:newLabel];

    [self.view addSubview:newView];
    [newLabel release];
    [newView release];
}

newView 看起来不错,但它不会以任何方式为自己设置动画,它只是立即出现.出现 newView 时如何添加某种动画?像缩放或向下滑动或类似的东西.有简单的代码吗?

newView appears fine, but it doesn't animate itself any way, it just appears immediately. How can I add some kind of animation when newView appears? Like zoom or slide down or something like that. Is there some simple code?

推荐答案

您可以使用 UIView 动画:

Hi You could use the UIView Animations:

[newView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
[UIView beginAnimations:@"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[newView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
[UIView commitAnimations];

SDK 现在会为您解决这个问题,并将视图动画化到您指定的位置.这适用于 UIViews 的大多数属性:alpha、scale、bounds、frames 等.

The SDK will now figure this out for you and animate the view to the positions you gave it. This works for most properties of UIViews: alpha, scale, bounds, frames, etc.

还有内置动画如翻转和卷曲:

There are also build in animations as flip and curl:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:newView
                            cache:YES];

[self.navigationController.view addSubview:settingsView.view];
[UIView commitAnimations];

希望这有助于您入门:)

Hope this helps out getting you started:)

这篇关于添加子视图动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆