2011-01-17 35 views
7

Xin chào các sự kiện cảm ứng, ứng dụng của tôi không xem hoạt ảnh. Nếu người dùng thực sự nhanh chóng và thực hiện một liên lạc khác ngay cả khi hoạt ảnh hiện tại đang diễn ra thì mọi thứ sẽ bị rối tung lên.Đồng bộ hóa hoạt ảnh UIView

Có cách nào tiêu chuẩn để xử lý vấn đề này do khung công tác cung cấp không? Hay tôi đang làm hoạt hình theo cách sai?

Hiện tại, bạn đang kiểm tra cờ (animationInProgress) để xử lý điều này nhưng tôi muốn biết liệu đó có phải là điều chúng tôi phải giải quyết cho điều này không?

Đây là mã:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    NSMutableArray *c = (NSMutableArray*)context; 
    UINavigationController *nc = [c objectAtIndex:0]; 
    [nc.view removeFromSuperview]; 
    animationInProgress = NO; 
} 

- (void)transitionViews:(BOOL)topToBottom { 
    if (animationInProgress) { 
     return; 
    } 
    animationInProgress = YES; 
    NSMutableArray *context = [[NSMutableArray alloc] init]; 
    [UIView beginAnimations:@"myanim" context:context]; 
    [UIView setAnimationDuration:0.7f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 

    UIViewController *from; 
    UIViewController *to; 
    if (navController3.view.superview == nil) { 
     from = navController2; 
     to = navController3; 
    } else { 
     from = navController3; 
     to = navController2; 
    } 

    int height; 
    if (topToBottom) { 
     height = -1 * from.view.bounds.size.height; 
    } else { 
     height = from.view.bounds.size.height; 
    } 

    CGAffineTransform transform = from.view.transform; 

    [UIView setAnimationsEnabled:NO]; 
    to.view.bounds = from.view.layer.bounds; 
    to.view.transform = CGAffineTransformTranslate(transform, 0, height); 
    [window addSubview:to.view]; 

    [UIView setAnimationsEnabled:YES]; 
    from.view.transform = CGAffineTransformTranslate(from.view.transform, 0, -1 * height); 
    to.view.transform = transform; 

    [context addObject:from]; 

    [UIView commitAnimations]; 

    return; 
} 

Trả lời

10

Hành vi mặc định của các khuôn khổ được, như bạn thấy, để cho phép bất cứ điều gì xảy ra cùng một lúc nếu bạn muốn nó.

Sử dụng cờ như bạn đang làm là hoàn toàn hợp lý nếu mục tiêu của bạn là chặn hoạt ảnh cụ thể xảy ra nếu nó đang chạy.

Nếu bạn muốn đi "lên mức" khái niệm và ngăn chặn bất kỳ sự kiện liên lạc từ khi vào ứng dụng của bạn ở tất cả trong phim hoạt hình, bạn có thể sử dụng:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 

cặp với a:

[[UIApplication sharedApplication] endIgnoringInteractionEvents]; 
+0

Nếu bạn dừng bất kỳ sự kiện chạm nào khi nhập ứng dụng của mình trong khi sử dụng hoạt ảnh bằng cách bắt đầu/kết thúcIgnoringInteractionEvents, điều gì sẽ xảy ra với các sự kiện chạm có thể đến khi đang ở trong khối này? Họ sẽ được lưu trữ và trình bày cho các ứng dụng một lần endIgnoringInteractionEvents được gọi là hoặc không ném đi tất cả các chạm (như tên cho thấy)? – vance

+0

@vance: Chúng sẽ bị vứt bỏ, như tên cho thấy. –

Các vấn đề liên quan