Почему пользовательский интерфейс блокируется после анимации? - PullRequest
0 голосов
/ 22 февраля 2011

У меня проблемы с простой анимацией.У меня есть UIImageView и невидимая кнопка поверх него.Когда эта кнопка нажата, изображение переходит в полноэкранный режим, когда пользователь нажимает в полноэкранном режиме, оно возвращается назад.Это отлично работает.Проблема в том, что при изменении размера изображения интерфейс блокируется (он не падает), он просто блокирует все взаимодействие с пользователем.Я не вижу, в чем проблема, хотя у меня есть теория, связанная с иерархией представления ...

Вот весь код для рассматриваемой анимации.

- (IBAction) imageButtonPressed {

NSLog(@"Entered imageButtonPressed method");

imageFullscreenView = [[UIImageView alloc] 
                       initWithFrame:CGRectMake(8, 72, 72, 72)];
[imageFullscreenView setImage:[self.coolView image]];
[imageFullscreenView setContentMode:UIViewContentModeScaleAspectFit];
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
[mainWindow addSubview:imageFullscreenView];

// With Concurrent Block Programming:
[UIView animateWithDuration:0.5 animations:^{
        [imageFullscreenView setFrame:CGRectMake(0, 0, 320, 480)];
        imageFullscreenView.transform = CGAffineTransformMakeScale(1, 1); 
        imageButton = [[[UIButton alloc] 
                       initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];

    [[[UIApplication sharedApplication] keyWindow] addSubview:imageButton];
    [[[UIApplication sharedApplication] keyWindow] 
                                        addSubview:imageFullscreenView];
    } completion: ^(BOOL finished) {
        NSLog(@"entered First animation");
        [self animationDidStop:@"Expand" finished:YES context:nil];
    }];

}

- (void) animationDidStop:(NSString *) animationID finished:(BOOL) 
                                 finished context:(void *)context {

NSLog(@"Entered animationDidStop");
NSLog(@"animationID: %@", animationID);
if ([animationID isEqualToString:@"Expand"]) {
    NSLog(@"Entered First if");
    NSLog(@"imageButton enabled: %d", self.imageButton.enabled);
    NSLog(@"coolButton enabled: %d", coolButton.enabled);
    NSLog(@"uncoolButton enabled: %d", uncoolButton.enabled);
    NSLog(@"reportButton enabled: %d", self.reportButton.enabled);
    imageButton.enabled = YES;
    imageButton = [[[UIButton alloc] 
                        initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
    [imageButton addTarget:self 
                         action:@selector(didViewFullscreen:) 
                         forControlEvents:UIControlEventTouchDown];
    [[[UIApplication sharedApplication] keyWindow] addSubview:imageButton];
    imageButtonPressed = NO;
} else {

}
}

- (void) didViewFullscreen: (id) selector {

NSLog(@"Entered didViewFullscreen");
[imageButton removeFromSuperview];
[UIView animateWithDuration:0.5 animations:^{
    [imageFullscreenView setFrame:CGRectMake(8, 72, 72, 72)];
} completion: ^(BOOL finished){
    NSLog(@"FINISHED");
    //NSLog(@"imageButton enabled: %d", self.imageButton.enabled);
    NSLog(@"coolButton enabled: %d", coolButton.enabled);
    NSLog(@"uncoolButton enabled: %d", uncoolButton.enabled);
    NSLog(@"reportButton enabled: %d", self.reportButton.enabled);
    //[imageFullscreenView setFrame:CGRectMake(20, 72, 280, 192)];
    imageFullscreenView.transform = CGAffineTransformMakeScale(1, 1);
    [imageFullscreenView removeFromSuperview];
    imageButton = [[[UIButton alloc] 
                      initWithFrame:CGRectMake(20, 72, 280, 192)] autorelease];
    [imageButton addTarget:self 
                         action:@selector(imageButtonPressed) 
                         forControlEvents:UIControlEventTouchUpInside];
    [imageButton setImage:nil forState:UIControlStateNormal];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self.imageButton];        
}];

}

Ответы [ 2 ]

3 голосов
/ 22 февраля 2011

В вашем методе animationDidStop:finished:context: вы снова создаете imageButton, не удаляя тот, который создан в методе imageButtonPressed.

[imageButton removeFromSuperview], прежде чем выделить другой, решит проблему.

1 голос
/ 22 февраля 2011

Вам лучше использовать

  • (void) animateWithDuration: (NSTimeInterval) длительность задержки: (NSTimeInterval) опции задержки: (UIViewAnimationOptions) опции анимации параметров: (void (^) (void)) завершение анимации: (void (^) (BOOL закончено)) завершение

с UIViewAnimationOptions, установленным на UIViewAnimationOptionAllowUserInteraction

Это не заблокирует вашUI.

...