iPhone SDK:输入一定数量的字符后,动画将不会加载 [英] iPhone SDK: After a certain number of characters entered, the animation just won't load

查看:59
本文介绍了iPhone SDK:输入一定数量的字符后,动画将不会加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是代码:

  [lblMessage setText:txtEnter.text]; 
[lblMessage sizeToFit];

scrollingTextView.contentSize = lblMessage.frame.size;
浮动宽度=(lblMessage.frame.size.width)+(480);

[UIView beginAnimations:@ pan上下文:无];
[UIView setAnimationDuration:durationValue];
[UIView setAnimationRepeatCount:5];
scrollingTextView.contentOffset = CGPointMake(width,0);
[UIView commitAnimations];

//滚动文本视图被旋转。
scrollingTextView.transform = CGAffineTransformMakeRotation(3.14 / 2);

[self.navigationController setNavigationBarHidden:YES];
btnChange.transform = CGAffineTransformMakeRotation(3.14 / 2);

我让用户输入一些文本,按一个按钮,然后用文本替换标签,在页面上的滚动视图中旋转了90度。



经过一定数量的字符(例如说20)之后,动画将不会加载。我可以一直走下去,直到动画开始运行。



关于我要去哪里的任何想法,或者有更好的存储文字等方式?

解决方案

核心动画是在单独的线程上执行的。当您在beginAnimations / commitAnimations块中包含contentOffset的更改时,该更改将逐渐被动画化。接下来在动画块之外发生的滚动文本视图旋转将立即执行。由于两者都与同一控件在不同线程上进行交互,因此出现奇怪的行为也就不足为奇了。



如果要对文本的旋转进行动画处理,与contentOffset相同,将这一行代码移动到动画块内。



如果要在偏移量更改动画完成后进行旋转,请设置回调委托方法。您可以在动画块的开头使用类似于以下内容的代码:

  [UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(contentOffsetAnimationHasFinished:finished:context :)];

这需要您实现如下所示的委托方法:

 -(void)contentOffsetAnimationHasFinished:(NSString *)animationID完成:(BOOL)完成的上下文:(void *)context; 
{
//现在第一个动画已完成
},然后做您需要做的事

编辑(2009年2月6日):
我只是使用横向滚动文本创建了应用程序的简化版本,并且发现设备上的动画没有任何问题字符数。我删除了所有多余的调用以布置按钮等,只为文本设置了动画。而不是每次单击按钮时都将旋转变换应用于滚动视图,而是让它开始旋转并保持这种状态。



我认为这可能是图层大小的问题,因为iPhone具有1024 x 1024的纹理大小限制(在此之后,您需要使用CATiledLayer来支持UIView) ,但是我能够布置超过1024像素的文本,并且仍然可以完成这项工作。 //www.sunsetlakesoftware.com/sites/default/files/TestOfRotatingText.zip rel = nofollow noreferrer>此处。我不知道您的问题是什么,但这与您在此处显示的文本动画代码无关。


Okay, this is the code:

[lblMessage setText: txtEnter.text];
[lblMessage sizeToFit];

scrollingTextView.contentSize = lblMessage.frame.size;
float width = (lblMessage.frame.size.width) + (480);

[UIView beginAnimations:@"pan" context:nil];
[UIView setAnimationDuration:durationValue];
[UIView setAnimationRepeatCount:5];
scrollingTextView.contentOffset = CGPointMake(width,0);
[UIView commitAnimations];

//The scrolling text view is rotated.
scrollingTextView.transform = CGAffineTransformMakeRotation (3.14/2);

[self.navigationController setNavigationBarHidden:YES];
btnChange.transform = CGAffineTransformMakeRotation (3.14/2);

I have the user enter in some text, press a button and then a label is replaced with the text, turned 90 degrees in a scrollview on a page.

After a certain number of characters, for example say 20.. the animation just won't load. I can go back down until the animation will run.

Any ideas on where I am going wrong, or a better way of storing the text etc etc ?

解决方案

Core Animation animations are performed on a separate thread. When you enclose the change in contentOffset in a beginAnimations / commitAnimations block, that change will be animated gradually. The scrolling text view rotation that occurs next, outside of the animation block, will be performed instantly. Since both are interacting with the same control on different threads, it's not surprising that you're getting weird behavior.

If you want to animate the rotation of the text in the same way as the contentOffset, move that line of code to within the animation block.

If you want to have the rotation occur after the offset change animation has completed, set up a callback delegate method. You can use code in the beginning of your animation block similar to the following:

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(contentOffsetAnimationHasFinished:finished:context:)];

which requires you to implement a delegate method like the following:

- (void)contentOffsetAnimationHasFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context;
{
// Do what you need to, now that the first animation has completed
}

EDIT (2/6/2009): I just created a simplified version of your application, using only the sideways text scrolling, and find no problem with the animation on the device with any number of characters. I removed all extraneous calls to layout the buttons, etc., and only animate the text. Rather than apply the rotation transform to the scroll view every time you click the button, I have it start rotated and stay that way.

I thought it might be a layer size issue, as the iPhone has a 1024 x 1024 texture size limit (after which you need to use a CATiledLayer to back your UIView), but I was able to lay out text wider than 1024 pixels and still have this work.

A full Xcode project demonstrating this can be downloaded here. I don't know what your issue is, but it's not with the text animating code you present here.

这篇关于iPhone SDK:输入一定数量的字符后,动画将不会加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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