如何在 obj c 中对具有一些文本的 uilabel 视图进行动画处理

发布于 2024-11-16 07:43:46 字数 735 浏览 2 评论 0原文

在我的应用程序中,我计划为 textLabels 添加动画,它应该来自屏幕的左侧,

我使用了以下代码,但它崩溃了

(void)animateLoop {

    UILabel *mylab;
    mylab.text=@"SAAAAdiiiii";
    mylab.frame = CGRectMake(-mylab.bounds.size.width, 100, mylab.bounds.size.width, mylab.bounds.size.height);
    [UIView beginAnimations:@"timesquare" context:nil];
    [UIView setAnimationDuration:5];
    [UIView setAnimationRepeatAutoreverses:(YES)];
    [UIView setAnimationRepeatCount:10];

    mylab.frame = CGRectMake(480, 100, mylab.bounds.size.width, mylab.bounds.size.height);

    [UIView commitAnimations]; 
 }

,我在 viewDidload 中调用了它

,但它在这一行崩溃了 mylab.text=@" SAAAAdiiii”; crashLog:invalidargument

谁能告诉我如何

提前为uilabel 设置动画

in my app i am planing to add the animation for the textLabels, which should come from left side of the screen

i have used following code but its crashing

(void)animateLoop {

    UILabel *mylab;
    mylab.text=@"SAAAAdiiiii";
    mylab.frame = CGRectMake(-mylab.bounds.size.width, 100, mylab.bounds.size.width, mylab.bounds.size.height);
    [UIView beginAnimations:@"timesquare" context:nil];
    [UIView setAnimationDuration:5];
    [UIView setAnimationRepeatAutoreverses:(YES)];
    [UIView setAnimationRepeatCount:10];

    mylab.frame = CGRectMake(480, 100, mylab.bounds.size.width, mylab.bounds.size.height);

    [UIView commitAnimations]; 
 }

n i called this in the viewDidload

but it was crashing at this line mylab.text=@"SAAAAdiiiii"; crashLog:invalidargument

can any one tell me how can i animate the uilabel

thanx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情归归情 2024-11-23 07:43:46

您需要分配 UILabel 。意味着首先为您的标签创建内存...

UILabel *mylab = [[UILabel alloc] initWithFrame:CGRectMake(x,y,width,height)];
mylab.text=@"SAAAAdiiiii";

建议您将 UILabel *mylab; 作为 iVar ,因为它必须释放

You need to alloced the UILabel . means first create the memory for you label ...

UILabel *mylab = [[UILabel alloc] initWithFrame:CGRectMake(x,y,width,height)];
mylab.text=@"SAAAAdiiiii";

Suggest you to have UILabel *mylab; as iVar , because it has to be released.

爱给你人给你 2024-11-23 07:43:46

您必须首先分配并初始化您的 UILabel..
而不是 UILabel *mylab; 尝试 UILabel *mylab = [[UILabel alloc] init];

您还必须在某个地方释放它,并且必须将标签添加到您的视图中(类似于[self.view addSubview:mylab];)。

You have to allocate and init your UILabel first..
instead of UILabel *mylab; try UILabel *mylab = [[UILabel alloc] init];

You also have to release it somewhere and you have to add the label to your view (something like [self.view addSubview:mylab];).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文