我看到我的应用程序中的所有ios动画都停止工作.它在iOS7中经常发生.
嘿家伙我有一个支持iOS 5,6和7的应用程序.我最近看到所有iOS动画都停止在iOS7的应用程序中工作?
Vin*_*mar 24
在IOS 7中,当在后台线程上执行某些主要方法操作时,动画将被禁用.
所以为此你需要重新启用动画,如(一种解决方法)
[UIView setAnimationsEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
可能这可以帮助.
Bri*_*kel 16
我最近遇到了一些问题,我正在为后台线程进行大小计算.通过调配setAnimationsEnabled:我发现我唯一一次从后台线程禁用动画-[UIImageView setImage:].
因为我的计算不需要渲染此视图并且不需要图像更改,所以我能够将此测试包含在主线程调用中:
if ([NSThread isMainThread]) {
self.answerImageView.image = [UIImage imageNamed:imgName];
}
Run Code Online (Sandbox Code Playgroud)
值得注意的是,我没有在初始视图实例化中遇到此问题,因为我已经在主线程中加载了我的模板视图以避免Xib加载问题.
其他问题可能更复杂,但您应该能够提出类似的解决方法.这是我用来检测动画背景禁用的类别.
#import <UIKit/UIKit.h>
#import <JRSwizzle/JRSwizzle.h>
#ifdef DEBUG
@implementation UIView (BadBackgroundBehavior)
+ (void)load
{
NSError *error = nil;
if (![self jr_swizzleClassMethod:@selector(setAnimationsEnabled:) withClassMethod:@selector(SE_setAnimationsEnabled:) error:&error]) {
NSLog(@"Error! %@", error);
}
}
+ (void)SE_setAnimationsEnabled:(BOOL)enabled
{
NSAssert([NSThread isMainThread], @"This method is not thread safe. Look at the backtrace and decide if you really need to be doing this here.");
[self SE_setAnimationsEnabled:enabled];
}
@end
#endif
Run Code Online (Sandbox Code Playgroud)
更新
事实证明,UIWebView实际上setAnimationsEnabled:在显示媒体元素时会进行不安全的调用(rdar:// 20314684).如果您的应用允许任意网络内容,这使得上述方法非常痛苦.相反,我已经开始使用以下方法,因为它允许我打开和关闭断点并在失败后继续:
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#ifdef DEBUG
void SEViewAlertForUnsafeBackgroundCalls() {
NSLog(@"----------------------------------------------------------------------------------");
NSLog(@"Background call to setAnimationsEnabled: detected. This method is not thread safe.");
NSLog(@"Set a breakpoint at SEUIViewDidSetAnimationsOffMainThread to inspect this call.");
NSLog(@"----------------------------------------------------------------------------------");
}
@implementation UIView (BadBackgroundBehavior)
+ (void)load
{
method_exchangeImplementations(class_getInstanceMethod(object_getClass(self), @selector(setAnimationsEnabled:)),
class_getInstanceMethod(object_getClass(self), @selector(SE_setAnimationsEnabled:)));
}
+ (void)SE_setAnimationsEnabled:(BOOL)enabled
{
if (![NSThread isMainThread]) {
SEViewAlertForUnsafeBackgroundCalls();
}
[self SE_setAnimationsEnabled:enabled];
}
@end
#endif
Run Code Online (Sandbox Code Playgroud)
使用此代码,您可以通过SEViewAlertForUnsafeBackgroundCalls在函数体中添加符号断点或仅断言断点来停止应用程序.
| 归档时间: |
|
| 查看次数: |
6545 次 |
| 最近记录: |