2012-08-09 15 views
5

Tôi muốn trình bày một bộ điều khiển xem toàn màn hình bán trong suốt để tôi vẫn nhìn thấy khung nhìn bên dưới nó. Đoạn mã sau trình bày bộ điều khiển khung nhìn mới, nhưng nó thay thế bộ điều khiển hiện tại. Cách tốt nhất để giữ bộ điều khiển chế độ xem ban đầu hiển thị là gì? Giao diện của trình điều khiển chế độ xem mới sẽ có nền đen nửa trong suốt.iOS - presentViewController với độ trong suốt

NewViewController* newVC = [[NSClassFromString(@"NewViewController") alloc] initWithNibName:deviceNib bundle:nil]; 
newVC.modalPresentationStyle = UIModalPresentationFullScreen; 
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 


[self presentViewController:newVC animated:YES completion:NULL]; 

Trả lời

6

Trình bày điều khiển xem trong suốt, không phải chế độ xem.

mySemiTransparentView.alpha = 0.0f; 
[self.view addSubview:mySemiTransparentView]; 

mySemiTransparentView là chế độ xem toàn màn hình. Bạn có thể animate nó vào vị trí:

[UIView beginAnimations:@"fadeIn" context:nil]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationDuration:0.4f]; 
mySemiTransparentView.alpha = 0.5f; 
[UIView commitAnimations]; 
+0

Đúng, nhưng tôi muốn sử dụng trình điều khiển chế độ xem. – soleil

+0

Bạn vẫn có thể khởi tạo UIViewController của mình thông qua alloc/init, sau đó mySemiTransparentView có thể chỉ là ViewController.view – CSmith

+2

của bạn trừ khi bạn muốn mọi thứ trên màn hình bán trong suốt là 0,5 alpha (bao gồm các nút và như vậy), không đặt alpha của xem vì nó xếp vào tất cả các thành phần phụ. Bạn nên tắt chế độ xem nền chiếm toàn bộ màn hình là 0,5 alpha và sau đó sắp xếp các nút của bạn và các nút đó lên đó. –

2

Bạn có thể trình bày điều khiển phương thức bán trong suốt theo cách sau:

NewViewController* newVC = [[NSClassFromString(@"NewViewController") alloc] initWithNibName:deviceNib bundle:nil]; 

self.modalPresentationStyle = UIModalPresentationCurrentContext; 
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 

[self presentViewController:newVC animated:YES completion:NULL]; 

Chú ý ở đây là bạn phải thiết lập hằng UIModalPresentationCurrentContext để tự .modalPresentationStyle, không phải là newVC .modalPresentationStyle

Ngoài ra, khi bạn sử dụng UIModalTransitionStyleCrossDissolve alpha của newVC.view sẽ được ghi đè trong quá trình chuyển, vì vậy nếu bạn muốn nền bán trong suốt, bạn sẽ cần phải giữ newVC.view 's backgroundColor rõ ràng và chỉ cần thêm một UIView như đó là chế độ xem phụ có bán trong suốt backgroundColor

+0

'self.modalPresentationStyle = UIModalPresentationCurrentContext;' hoặc 'newVC. modalPresentationStyle = UIModalPresentationCustom'and + 1 cũng cho phần thứ hai của câu trả lời của bạn. Cảm ơn –