从 __block typeof(self) blockSelf 呈现半透明模态视图
Presenting a semi-transparent modal view from __block typeof(self) blockSelf
我很难尝试让 iOS 7 工作,但它对 iOS 8 工作正常。
我有一个透明的模态视图从父级 vc 呈现,它是导航视图控制器层次结构的一部分。模态视图按预期动画到位,但随后底层父视图消失。
模态视图完成工作后,它被关闭,我 return 到呈现视图控制器。但我希望呈现 vc 在模态视图显示在屏幕上时保持原位。
我已经尝试了几乎所有来自 SO 的建议,例如设置呈现的模态呈现样式 vc、设置定义上下文等等,但是 none 的解决方案对我有用.
为什么这在 iOS 8 中如此简单而在 iOS 7 中却如此困难?
__block typeof(self) blockSelf = self;
void (^completionBlock)(POJSONResponse *obj, NSError *err) = ^(POJSONResponse *obj, NSError *error) {
if (error == nil) {
// display a transparent modal view
UINavigationController *navController = blockSelf.navigationController;
ModalViewController *mvc = [[ModalViewController alloc] init];
[mvc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[navController presentViewController:mvc animated:YES completion:nil];
这在 iOS 7 中很难,因为 UIModalPresentationOverCurrentContext
在 iOS 8 中是新的。如果你想在 iOS 7 中实现这种效果,你需要全部完成你自己。
参见 How to present a semi-transparent (half-cut) viewcontroller in iOS?,尤其是显示如何将 UIModalPresentationCustom
与自定义 SemiModalAnimatedTransition
一起使用的答案。
我很难尝试让 iOS 7 工作,但它对 iOS 8 工作正常。
我有一个透明的模态视图从父级 vc 呈现,它是导航视图控制器层次结构的一部分。模态视图按预期动画到位,但随后底层父视图消失。
模态视图完成工作后,它被关闭,我 return 到呈现视图控制器。但我希望呈现 vc 在模态视图显示在屏幕上时保持原位。
我已经尝试了几乎所有来自 SO 的建议,例如设置呈现的模态呈现样式 vc、设置定义上下文等等,但是 none 的解决方案对我有用.
为什么这在 iOS 8 中如此简单而在 iOS 7 中却如此困难?
__block typeof(self) blockSelf = self;
void (^completionBlock)(POJSONResponse *obj, NSError *err) = ^(POJSONResponse *obj, NSError *error) {
if (error == nil) {
// display a transparent modal view
UINavigationController *navController = blockSelf.navigationController;
ModalViewController *mvc = [[ModalViewController alloc] init];
[mvc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[navController presentViewController:mvc animated:YES completion:nil];
这在 iOS 7 中很难,因为 UIModalPresentationOverCurrentContext
在 iOS 8 中是新的。如果你想在 iOS 7 中实现这种效果,你需要全部完成你自己。
参见 How to present a semi-transparent (half-cut) viewcontroller in iOS?,尤其是显示如何将 UIModalPresentationCustom
与自定义 SemiModalAnimatedTransition
一起使用的答案。