1

我得到以下代码:

- (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 driver[5912:907]-[NSISRestrictedToNonNegativeVariable count]:无法识别的选择器发送到实例 0x1dd3aea0 2013-02-07 18:16:21.679 driver[5912:907] * 由于未捕获而终止应用程序异常“NSInvalidArgumentException”,原因:“-[NSISRestrictedToNonNegativeVariable 计数]:无法识别的选择器发送到实例 0x1dd3aea0”*First throw call stack: (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 called throwing an exception

相应的堆栈跟踪如下所示: 在此处输入图像描述

或类似的东西:

驱动程序(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 元素在哪里可以在这 0.5 秒内被破坏?

4

1 回答 1

0

问题不在于您粘贴的代码 - 问题在于动画开始后它引用的视图发生了什么(代码中的其他位置)。如果动画运行了 0.5 秒,那么所有这些视图必须在接下来的 0.5 秒内仍然处于活动状态。

因此,您对寿命不够长的视图的选择:self、self.waiting_view、self.waiting_label、self.activity_indicator。

于 2013-02-07T17:51:50.603 回答