-4

我下载的某些控件有问题,我想在按下按钮时更改背景,但似乎按下按钮时,应用程序在当前事件完成之前不会监听任何事件这是我的代码

-(void) menuItem:(RRCircularItem *)item didChangeActive:(BOOL)active {

    [menu progress];
    [menu setBackgroundColor1:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuabiertoloadingretina.png"]]];
    [menu hideWithAnimationBlock:^{
        self.view.backgroundColor = [UIColor whiteColor];
    }];
    [menu release], menu = nil;
     self.viewCarga.hidden = NO;
    [menu setBackgroundColor1:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuabiertoloadingretina.png"]]];
    NSLog(@"Item %@ did change state to %d", item.text, active);
    if ([item.text isEqualToString:@"EDITORIALES"]){

        ViewController *viewControler = [[ViewController alloc] initWithNibName:@"EditorialesViewController" bundle:nil];
        [self presentViewController:viewControler animated:YES completion:nil];
        [menu setBackgroundColor1:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuabiertoloadingretina.png"]]];

    }else if ([item.text isEqualToString:@"GOLES"]){

        GolViewController *viewControler = [[GolViewController alloc] initWithNibName:@"GolViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }else if ([item.text isEqualToString:@"TABLA"]){

        WebViewController *viewControler = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }else if ([item.text isEqualToString:@"AUNLI"]){

        AUNLIViewController *viewControler = [[AUNLIViewController alloc] initWithNibName:@"AUNLIViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }else if ([item.text isEqualToString:@"HORARIOS"]){

        HorariosViewController *viewControler = [[HorariosViewController alloc] initWithNibName:@"HorariosViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }

    if (active && ![menu isLabelActive]) {
        [menu setLabelActive:YES];
        [menu setSliderValue:1];
    } else if (!active && [menu isLabelActive]) {
        BOOL hasActive = NO;
        for (int i = 0; i < 6; i++) hasActive |= [menu isItemActive:i];
        if (!hasActive) {
            [menu setLabelActive:NO];
            [menu setSliderValue:0 animated:NO];
        }
    }
}

我想[menu progress];在一切之前使用这个事件,但它不起作用。

4

1 回答 1

0

如果我明白了,你按下一些按钮然后你就保持锁定状态。这是因为你在主线程中做所有事情。这就是您需要使用线程的原因,这样您将执行多个同步/异步进程以防止应用程序中的锁定。您可以使用 NSThread、dispatch 或 NSOperationQueue...我喜欢使用 GCD(Grand Central Dispatch)

样本:

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
    //Background Thread
    dispatch_async(dispatch_get_main_queue(), ^(void){
        //User Interface Updates
    });
});
于 2013-07-01T19:35:28.533 回答