2015-06-23 14 views
28

Tôi đã trình bày màn hình đăng nhập như sau. Đúng nếu tôi không đúng.Trình bày chế độ xem phương thức bằng hoạt ảnh mờ dần

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];//LOOK AT NEXT LINE 
    [self presentViewController:ivc animated:YES completion:nil]; 

Màn hình đăng nhập xuất hiện nhưng hoạt ảnh là trang chiếu lên một. Tôi thích mờ dần và làm mờ hoạt hình của chúng tôi. Tôi có thể làm cái này như thế nào?

+0

thể trùng lặp của [Làm thế nào tôi có thể thay đổi phong cách hoạt hình của một UIViewController modal?] (Http://stackoverflow.com/questions/237310/how-can-i-change-the-animation-style-of-a-modal-uiviewcontroller) –

Trả lời

71

Chỉ cần đặt các thuộc tính modalPresentationStylemodalTransitionStyle cho chế độ xemController.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"]; 
[ivc setModalPresentationStyle:UIModalPresentationCustom]; 
[ivc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
[self presentViewController:ivc animated:YES completion:nil]; 
+1

Của bạn là một cách tốt hơn so với [this one] (http://stackoverflow.com/questions/237310/how-can-i-change-the-hoạt hình-phong cách-of-a-modal-uiviewcontroller). –

+5

Vâng, đó là câu trả lời từ năm 2008. Tôi chắc chắn rằng các thuộc tính này không có sẵn tại thời điểm đó. Nếu bạn nhìn vào câu trả lời được bình chọn nhiều nhất ở đó, bạn sẽ thấy họ đã gợi ý điều tương tự. – ZeMoon

+0

Tôi phải thừa nhận là tôi đã bỏ lỡ những cái đó. –

29

Swift 3, 3.1(tính đến 02 tháng 8 2017)

var storyboard = UIStoryboard(name: "Main", bundle: nil) 
var ivc = storyboard.instantiateViewController(withIdentifier: "login") 
ivc.modalTransitionStyle = .crossDissolve 
self.present(ivc, animated: true, completion: { _ in }) 
+5

Đặt 'modalPresentationStyle' là không cần thiết. Trong thực tế, [các tài liệu] (https://developer.apple.com/reference/uikit/uimodalpresentationstyle/1621375-custom) chỉ định rằng '.custom' chỉ nên được sử dụng kết hợp với' transitioningDelegate'. – clozach

+0

Đã chỉnh sửa với .custom bị xóa. Cảm ơn @clozach vì mẹo! – BennyTheNerd

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