2008-10-26 25 views
69

Tôi hiện đang hiển thị một UIViewController như thế này:Làm cách nào để thay đổi kiểu hoạt ảnh của UIViewController phương thức?

[[self navigationController] presentModalViewController:modalViewController animated:YES]; 

và giấu nó như thế này:

[self.navigationController dismissModalViewControllerAnimated:YES]; 

Các hình ảnh động là "trượt lên từ đáy" ... sau đó trượt xuống. Làm cách nào để thay đổi kiểu hoạt ảnh? Tôi có thể làm cho nó mờ dần vào/ra?

Chúc mừng!

Trả lời

60

Marcus Zarra đăng một giải pháp tuyệt vời để này vào danh sách gửi thư SDK:

UIViewController *controller = [[[MyViewController alloc] init] autorelease]; 
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp; 
[UIView beginAnimations: nil context: nil]; 
[UIView setAnimationTransition: trans forView: [self window] cache: YES]; 
[navController presentModalViewController: controller animated: NO]; 
[UIView commitAnimations]; 

Có hiệu ứng chuyển tiếp cho lật và trang-uốn. Nếu bạn được đặt ở chế độ mờ dần, bạn có thể thử điều chỉnh chế độ xem alpha mới của mình:

UIViewController *controller = [[[MyViewController alloc] init] autorelease]; 
controller.view.alpha = 0.0; 
[navController presentModalViewController: controller animated: NO]; 
[UIView beginAnimations: nil context: nil]; 
controller.view.alpha = 1.0; 
[UIView commitAnimations]; 

Tuy nhiên, những gì bạn có thể muốn là ghép hoặc ít nhất là mờ dần. Khi UINavigationController chuyển sang chế độ xem mới, nó sẽ loại bỏ chế độ xem cũ. Đối với hiệu ứng này, bạn có lẽ tốt hơn hết chỉ cần thêm một cái nhìn mới cho UIViewController hiện tại của bạn và mờ dần alpha của nó theo thời gian.

Lưu ý: Nếu bạn không ở trong ứng dụng ủy quyền [cửa sổ tự] sẽ không hoạt động. Sử dụng self.view.window, nhờ vào bài viết của user412500 để chỉ ra điều này.

+5

Đây là cũ! Xem câu trả lời của Simo Salminen dưới đây! MrDatabase bạn nên chuyển đổi này –

194

Đối với iPhone 3.0+, một crossfade cơ bản là dễ nhất để làm như thế này:

modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
[[self navigationController] presentModalViewController:modalViewController 
               animated:YES]; 
+2

Hoạt động hoàn hảo !!! Nó đã cho tôi một vài giây để nhận ra rằng quá trình chuyển đổi đã được áp dụng cho viewController đang được trình bày và không phải là tự. – looneydoodle

+0

Bạn có thể làm điều này trong Interface Builder, bằng cách thêm một phân đoạn phương thức và thiết lập chuyển đổi sang 'Cross Dissolve', chẳng hạn. – paulvs

2

Nó phải là [self.view.window] để cho mã để làm việc

(ít nhất đó là cách mà nó là trong ios 3,2)

8

để cập nhật cho alpha mờ dần trong iOS 4:

modalController.view.alpha = 0.0; 
[self.view.window.rootViewController presentModalViewController:modalController animated:NO]; 
[UIView animateWithDuration:0.5 
       animations:^{modalController.view.alpha = 1.0;}]; 
+1

Điều này làm việc tuyệt vời cho tôi. – zekel

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