2012-05-24 35 views
6

Tôi loại bỏ một bộ điều khiển chế độ xem phương thức và sau đó ngay lập tức trình bày một bộ điều khiển chế độ xem khác tuy nhiên tôi hiện không thể sử dụng hoạt ảnh trên cả hai bộ điều khiển chỉ thứ hai.Làm cách nào để trì hoãn giữa 2 hoạt ảnh?

Có cách nào để trì hoãn quá trình để người dùng trải nghiệm cả hình động?

Mã dưới đây hiện đang hoạt động tuy nhiên người dùng chỉ nhìn thấy các hình ảnh động thứ hai rõ ràng là:

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

//Dismiss first one 
[self dismissModalViewControllerAnimated:NO]; 

//Immediately configure and show second one 
navController.modalPresentationStyle = UIModalPresentationFormSheet; 
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:navController animated:YES]; 
+0

tôi có thể giả sử bạn đã cố gắng ' [tự dismissModalViewControllerAnimated: YES]; 'không sự thành công?? –

+0

[UIView transitionWithView: mysuperview duration: 0.75 tùy chọn: UIViewAnimationTransitionFlipFromRight animations:^{[self dismissModalViewControllerAnimated: NO]; } hoàn thành: nil] –

Trả lời

9

Hiện tại, có một khối hoàn thành có sẵn trong bộ điều khiển chế độ xem hiện tại. Xem này LINK. Tính năng này có sẵn trong iOS5.0 +.

Điều này có lợi thế là bạn không cần phải ước tính độ trễ bộ hẹn giờ nếu bạn sử dụng giải pháp hẹn giờ.

Chỉ cần đặt mã cho phim hoạt hình thứ hai của bạn trong khối:

//Block safe reference to self to prevent retain cycles 
__block typeof (self) selfReference = self; 

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES completion: 
^{ 
    //Dismiss first one 
    [selfReference dismissModalViewControllerAnimated:NO]; 

    //Immediately configure and show second one 
    navController.modalPresentationStyle = UIModalPresentationFormSheet; 
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [selfReference presentModalViewController:navController animated:YES]; 
}]; 
+2

Đây là giải pháp đúng. Cố gắng sử dụng bộ hẹn giờ để đoán thời điểm bộ điều khiển xem đầu tiên của bạn kết thúc hoạt ảnh là một hack. – jnic

+0

+1 Đối với một trong những cách tiếp cận tốt nhất – Mat

+0

Điều này thật tuyệt vời! Hai hình ảnh động tuyệt vời cùng nhau nhờ bạn đời, cộng với lần đầu tiên sử dụng các khối - rất tiện dụng! – TheLearner

1

Thực hiện một selector nào sau đây:

- (void)showSecondModalVC { 
    //Dismiss first one 
    [self dismissModalViewControllerAnimated:NO]; 

    //Immediately configure and show second one 
    navController.modalPresentationStyle = UIModalPresentationFormSheet; 
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:navController animated:YES]; 
} 

Một sau đó trong phần chính của mã:

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

[self performSelector:@selector(showSecondModalVC) 
     withObject:nil 
     afterDelay:0.5f]; 

Bạn sẽ phải xem xét kỹ lưỡng và xem nó tốn bao nhiêu cho phương thức đầu tiên để cho thấy các hoạt ảnh trông thật tuyệt.

1

Bạn có thể làm điều đó trong một số phong cách khác.

detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

[self dismissModalViewControllerAnimated:NO]; 

[self performSelector:@selector(someFunction) withObject:nil afterDelay:1.0]; 

- (void) someFunction{ 
//Immediately configure and show second one 
navController.modalPresentationStyle = UIModalPresentationFormSheet; 
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:navController animated:YES]; 

}

1

Hãy thử với điều này:

// First one configure 
detailViewController.modalPresentationStyle = UIModalPresentationFullScreen; 
detailViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:detailViewController animated:YES]; 

//Dismiss first one 
[self dismissModalViewControllerAnimated:NO]; 
NSTimer Timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(openSecondView) userInfo:nil repeats:NO]; 


-(void)openSecondView 
{ 
    //Immediately configure and show second one 
    navController.modalPresentationStyle = UIModalPresentationFormSheet; 
    navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:navController animated:YES]; 
} 

Chúc mừng Mã hóa ...

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