IOS: ModalView с прозрачным фоном?
Я хочу показать modalview на viewController. (который имеет контроллер навигации).
На мой взгляд у меня есть текст и кнопка, чтобы показать modalview.
Я создал .xib, который содержал мой modalview (это представление с изображением и меткой).
Когда я покажу его, с этим:
ShareController *controller = [[ShareController alloc] initWithNibName:@"ShareController" bundle: nil];
controller.view.backgroundColor = [UIColor clearColor];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:controller animated:YES completion:nil];
У меня есть мой modalview, НО, фон становится черным.. и я хочу всегда видеть текст на моем представлении. (я пытался установить альфа и т.д., но NOTHING работает: '()
Кто-нибудь, кто поможет мне?
Спасибо,
Ответы
Ответ 1
вы можете проверить пример iOS7 (см. мой комм) или просто попробуйте это:
удалите эту строку из вашего метода "представления"
controller.view.backgroundColor = [UIColor clearColor];
теперь, в viewDidLoad ShareController
add:
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalPresentationStyle = UIModalPresentationFormSheet;
PS
если у вас есть navigationController... используйте
[self.navigationController presentViewController:controller animated:YES completion:nil];
Ответ 2
Используйте следующий фрагмент, чтобы сделать это на iOS 8 и более поздних версиях:
Для цели C:
UIViewController *walkThru = [self.storyboard instantiateViewControllerWithIdentifier:@"WalkThroughScene"];
walkThru.providesPresentationContextTransitionStyle = YES;
walkThru.definesPresentationContext = YES;
[walkThru setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self.navigationController presentViewController:walkThru animated:YES completion:nil];
Для Swift 2:
let viewController : XYZViewController = self.storyboard!.instantiateViewControllerWithIdentifier("XYZIdentifier") as! XYZViewController
viewController.providesPresentationContextTransitionStyle = true
viewController.definesPresentationContext = true
viewController.modalPresentationStyle=UIModalPresentationStyle.OverCurrentContext
self.presentViewController(viewController, animated: true, completion: nil)
Для Swift 4:
let viewController = self.storyboard!.instantiateViewController(withIdentifier: "XYZIdentifier") as! XYZViewController
viewController.providesPresentationContextTransitionStyle = true
viewController.definesPresentationContext = true
viewController.modalPresentationStyle = .overCurrentContext
self.present(viewController, animated: true, completion: nil)
И цвет фона вашего представленного viewController должен быть clearColor.
Ответ 3
Если вы хотите, чтобы ваш modalVC находился над вкладкой, вам необходимо определить стиль презентации как UIModalPresentationOverFullScreen
[_presentedViewController setModalPresentationStyle:UIModalPresentationOverFullScreen];
[_presentingViewController presentViewController:_presentedViewController animated:YES completion:nil];
Ответ 4
Быстрый ответ: вы не можете представить прозрачный модальный вид, а не с помощью метода currentViewController: анимированный: завершение:. Потому что вы не можете сделать прозрачный контроллер модального просмотра (ваш вид - россыпи поверх этого).
Вы можете создать пользовательский вид, и вы можете вручную его анимировать, это способ создать что-то, что вам нужно.
Ответ 5
В PresentingViewController
скопируйте приведенный ниже код в разделе раскадровки segue или IBAction.
SecondViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];
//SecondViewController *viewController = [SecondViewController alloc]init]; // if you are adding the viewcontroller programatically
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[viewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:viewController animated:YES completion:nil];
Во втором ViewController
выполните следующие шаги либо с помощью раскадровки, либо с помощью кода:
- Установите цвет фона представления (
self.view
) на clearcolor и уменьшите непрозрачность до 50%
- Теперь вы можете реализовать полупрозрачный вид модальности
Ответ 6
Это цвет UIWindow's
, вы можете инициализировать цвет UIWindow
в appDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
return YES;
}
Ответ 7
Swift 3 Pankaj Отвечать:
let stb = UIStoryboard(name: YOUR_STORYBOARD, bundle: nil)
let vc = stb.instantiateViewController(withIdentifier: YOUR_POPUP_IDENTIFIER)
vc.providesPresentationContextTransitionStyle = true
vc.definesPresentationContext = true
vc.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext
self.present(vc, animated: true, completion: nil)