Objective c 目标c中的代码执行
大家好,如果我有这样的事情:Objective c 目标c中的代码执行,objective-c,uiactivityindicatorview,Objective C,Uiactivityindicatorview,大家好,如果我有这样的事情: my code.... // active indicator activity [otherClass method]; // method that takes 5-6 seconds // disable indicator activity my code... 调用long方法时,类中的代码被阻止了,对吗 如果我在调用该方法之前激活了一个指示器活动,它将在“方法”执行时动画化 谢谢。 你应该避免阻塞主线程这么长时间,考虑在单独的线程中把方法分成两个运行
my code....
// active indicator activity
[otherClass method]; // method that takes 5-6 seconds
// disable indicator activity
my code...
调用long方法时,类中的代码被阻止了,对吗
如果我在调用该方法之前激活了一个指示器活动,它将在“方法”执行时动画化
谢谢。
你应该避免阻塞主线程这么长时间,考虑在单独的线程中把方法分成两个运行<强> [其他类方法] <强>。主线程用于UI更新,不确定指示器是否能够用主线程阻塞,我想不是。
您应该避免阻塞主线程这么长时间,考虑在单独线程中将该方法分成两个运行<强> [其他类方法] < /强>。主线程用于UI更新,不确定指示器是否能够在主线程被阻止的情况下运行,我认为不会。
是的,除非您在另一个线程中运行long方法,否则它将被阻止要做到这一点,请使用以下技术。请参见performSelectorInBackground和performSelectorOnMainThread是,除非您在另一个线程中运行long方法,否则它将被阻止
要做到这一点,请使用以下技术。请参见performSelectorInBackground和performSelectorOnMainThread正如iceydee所提到的,UI元素(如活动指示器)在主线程上运行。如果你加载一个大文件,下载一些东西或者任何其他需要时间的东西,如果你想给UI元素设置动画,你必须在其他线程上执行。您可以使用Grand Central Dispatch、PerformSelector Background或其他技术(不推荐)。我想提出:
my code....
// active indicator activity
[otherClass performSelectorInBackground:@selector(method) withObject:nil]; // method that takes 5-6 seconds
my code...
然后在otherClass的方法中,停止主线程上的活动指示器:
[activityIndicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
正如iceydee所提到的,UI元素(如活动指示器)在主线程上运行。如果你加载一个大文件,下载一些东西或者任何其他需要时间的东西,如果你想给UI元素设置动画,你必须在其他线程上执行。您可以使用Grand Central Dispatch、PerformSelector Background或其他技术(不推荐)。我想提出:
my code....
// active indicator activity
[otherClass performSelectorInBackground:@selector(method) withObject:nil]; // method that takes 5-6 seconds
my code...
然后在otherClass的方法中,停止主线程上的活动指示器:
[activityIndicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
我不确定你的问题是什么?您是否在问如果启用动画,它是否会继续播放?如果是这样的话,这将取决于你的应用程序如何工作。我不确定你的问题是什么?您是否在问如果启用动画,它是否会继续播放?如果是这样的话,这将取决于你的应用程序的工作方式。