我收到了以下代码:
- (void) hide_waiting_activity
{
[UIView beginAnimations:nil context:NULL]; {
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
} [UIView commitAnimations];
}
问题:它有时崩溃,有时不崩溃。如果它崩溃,控制台输出看起来像这样:
2013-02-07 18:16:21.658司机[5912:907] - [NSISRestrictedToNonNegativeVariable count]:无法识别的选择器发送到实例0x1dd3aea0 2013-02-07 18:16:21.679驱动程序[5912:907] *由于未捕获的异常'NSInvalidArgumentException'而终止应用,原因: ' - [NSISRestrictedToNonNegativeVariable count]:无法识别的选择器 发送到实例0x1dd3aea0' * 第一次抛出调用堆栈:(0x342e03e7 0x3bfd1963 0x342e3f31 0x342e264d 0x3423a208 0x34c90d5b 0x34c9a6c3 0x34c9a56f 0x34c9a781 0x34c9acf1 0x34c99d6b 0x34c9ac31 0x34c92393 0x34c94f01 0x34c95ed7 0x34c9ecab 0x36527519 0x36527689 0x365277ab 0x3652791f 0x36527acf 0x34c95997 0x36527a41 0x3652aad1 0x3652d0d9 0x3652cfe3 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34226acd 0x3652cf97 0x34c95997 0x36526f3d 0x361623dd 0x35e9e513 0x35e9e0b5 0x35e9efd9 0x35e9e9c3 0x35e9e7d5 0x35e9e639 0x342b5941 0x342b3c39 0x342b3f93 0x3422723d 0x342270c9 0x37e0533b 0x361432b9 0xd3871 0xc29d8)libc ++ abi.dylib:terminate叫做throw 例外
相应的堆栈跟踪如下所示:
或类似的东西:
驱动程序(5930,0x3df85b78)malloc: *对象0x1e565990的错误: 正在释放的指针未分配 * 在malloc_error_break中设置断点以调试(lldb)
然后堆栈跟踪看起来像
我完全无能为力。有人有想法吗?我正在使用ios 6.1。
更新: 注释内部嵌套括号不会改变任何内容:
[UIView beginAnimations:nil context:NULL]; {
//[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
} [UIView commitAnimations];
更新2: 删除大括号后,应用程序仍会按照描述崩溃。
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
[UIView commitAnimations];
更新3: 这是包含hide_waiting_activity中任何受影响的ui元素的完整代码:
MainNavigationController.h
//Waiting overlay
@property (nonatomic,strong) UIActivityIndicatorView* activity_indicator;
@property (nonatomic,strong) UIImageView* waiting_view;
@property (nonatomic,strong) UILabel* waiting_label;
MainNavigationController.m
@implementation MainNavigationController
@synthesize activity_indicator;
@synthesize waiting_view;
@synthesize waiting_label;
...
- (void)viewDidLoad
{
[super viewDidLoad];
//Create a transparent waiting indicator view that is shown to the user while the app is working in background
waiting_view = [[UIImageView alloc] initWithFrame:CGRectMake( 0, 64.f /* top navigation bar is 64.f */, 320, 480 )];
[waiting_view setImage:[UIImage imageNamed:@"Main_Menu_Background.png"]];
waiting_view.backgroundColor = [UIColor clearColor];
self.activity_indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.activity_indicator setColor:[UIColor blackColor]];
[self.activity_indicator startAnimating];
self.activity_indicator.center = CGPointMake( 160.f, (240.f-64.f) );
[waiting_view addSubview:activity_indicator];
waiting_label = [[UILabel alloc] initWithFrame:CGRectMake( 110.f, (240.f-64.f)+30.f, 100.f, 16.f)];
waiting_label.font = [UIFont boldSystemFontOfSize:13.f];
waiting_label.textColor = [UIColor blackColor];
waiting_label.backgroundColor = [UIColor clearColor];
waiting_label.textAlignment = UITextAlignmentCenter;
waiting_label.text = NSLocalizedString(@"Please_Wait_Text", @"");
[waiting_view addSubview:waiting_label];
[self.view addSubview:waiting_view];
[self.view bringSubviewToFront:self.activity_indicator];
self.waiting_view.hidden = YES;
self.activity_indicator.hidden = YES;
...
}
- (void) show_waiting_activity
{
if( self.waiting_view.alpha == 1 && self.waiting_view.hidden == NO )
return;
self.waiting_view.hidden = NO;
self.activity_indicator.hidden = NO;
[UIView beginAnimations:nil context:NULL]; {
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.2];
self.waiting_view.alpha = 1;
self.waiting_label.alpha = 1;
self.activity_indicator.alpha = 1;
} [UIView commitAnimations];
}
- (void) hide_waiting_activity
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:.5];
self.waiting_view.alpha = 0;
self.waiting_label.alpha = 0;
self.activity_indicator.alpha = 0;
[UIView commitAnimations];
}
我问自己在这段代码中,ui元素在这些.5秒内可以被销毁?
答案 0 :(得分:0)
问题不在于您粘贴的代码中 - 问题是在动画启动后(代码中的其他位置)引用的视图发生了什么。如果动画运行0.5秒,则所有这些视图必须在接下来的0.5秒内仍处于活动状态。
所以,你选择的观点不够长:self,self.waiting_view,self.waiting_label,self.activity_indicator。