如何在 obj c 中对具有一些文本的 uilabel 视图进行动画处理
在我的应用程序中,我计划为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要分配 UILabel 。意味着首先为您的标签创建内存...
建议您将
UILabel *mylab;
作为iVar
,因为它必须释放
。You need to alloced the UILabel . means first create the memory for you label ...
Suggest you to have
UILabel *mylab;
asiVar
, because it has to bereleased
.您必须首先分配并初始化您的 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;
tryUILabel *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];
).