我试图以模糊方式呈现视图控制器,具有透明背景.我的目标是让呈现和呈现的视图控制器视图同时显示.问题是,当呈现动画结束时,呈现视图控制器的视图消失.
- (IBAction)pushModalViewControllerButtonPressed:(id)sender
{
ModalViewController *modalVC = [[ModalViewController alloc] init];
[self presentViewController:modalVC animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将视图添加为子视图,但出于某种原因我想避免使用此解决方案.我该怎么办呢?
objective-c modalviewcontroller presentmodalviewcontroller ios
我有一个UIViewController子类作为故事板中的一个场景,其中包含一个UIScrollView包含各种子视图的场景.其中一个子视图是一个UIButton分割成另一个场景UIViewController子类的子视图.当我从视图回来(弹出UIViewController关闭导航控制器堆栈),我发现,滚动视图的起源已经在某种程度上改变了,虽然contentsize和contentoffset似乎是正确的.
有趣的是,该应用程序有一个标签栏,当我离开并返回到该视图时,滚动视图正确设置,偏移量为(0,0).
这个过程基本上没有涉及代码,因为它几乎都在故事板中.由于我对使用故事板相当新,我觉得我做错了什么,虽然我不知道是什么.关于那可能是什么的任何想法?也许是调整问题或限制?
在iOS 7之前,根据这个流行的Stackoverflow 问题,显示具有清晰背景的ViewController的方法是在主ViewController中执行以下操作:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
但是,正如我最近在iOS 7中发现的那样(以及其他人对主要答案的评论),上述解决方案不再有效,而只是显示了黑色模型控制器.我知道透明度主要用于iOS 7,因此透明视图控制器很有可能.我还没有发现这个问题的解决方法,并且想知道是否有人知道如何解决这个问题.谢谢!
我正在尝试自己制作一个自定义alertView(适用于iOS7 +),但我在使用alertView演示文稿时遇到了困难.
我有一个黑色背景的UIViewController(alpha设置为0.25f),以及一个alertView作为子视图.
当我想显示alertView时,我以模态方式呈现viewController:
-(void) show
{
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
self.modalTransitionStyle = UIModalPresentationCustom;
self.transitioningDelegate = self;
[window.rootViewController presentViewController:self animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是我的动画师对象:
-(NSTimeInterval) transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
NSLog(@"%s",__PRETTY_FUNCTION__);
return 2;
}
-(void) animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
NSLog(@"%s",__PRETTY_FUNCTION__);
UIView* toView = [transitionContext viewForKey:UITransitionContextToViewKey];
toView.alpha = 0;
UIView* container = [transitionContext containerView];
[container addSubview:toView];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toView.alpha = 0.5;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
Run Code Online (Sandbox Code Playgroud)
事情是:模态VC在背景中呈现VC呈现淡化,但是当动画结束时,呈现VC将从背景中移除.
如果我[transitionContext completeTransition:YES];改为调用,则呈现VC在后台但是在动画结束时删除了模态VC,所以如果我们发送'NO',我猜上下文取消了演示.
有没有办法将演示VC保留在后台而不必创建它的快照并将其设置为模态VC视图的背景?
我想以UIViewController编程方式呈现一个应该以透明背景显示(或不显示)的内容.我希望它适用于iOS 7.0及更高版本.我发现自己有很多问题(和答案),但他们无法帮助我.这是我的应用程序的视图层次结构.
我正在使用侧面菜单控制器(RESideMenu).
我有一个rootView(来自RESideMenu的基础) - >显示一个中心控制器(以及一个左视图控制器)UINavigationController.
在要求中,我想呈现一个视图控制器
从推动的视图控制器(在导航层次结构中)
从呈现的视图控制器(在导航层次结构中)
另外,我需要呈现它并执行一些操作,然后将其删除.
我很确定这应该适用于许多情况,有(或没有)侧面菜单,甚至导航控制器.
我在这个队列中发布了一个单独的问题(当然也是它的答案),因为我认为这对社区开发者有帮助,他们可能也因为缺乏可接受的解决方案而感到沮丧.
uiviewcontroller uinavigationcontroller ios presentviewcontroller
我有VC,我想推动它并看到它下面的VC.
如果我以模态方式呈现(在UIViewController上显示clearColor UIViewController),我可以这样做
但是可以通过推送VC实现这个功能吗?或者我需要创建自定义过渡?
uiviewcontroller uiview uinavigationcontroller pushviewcontroller ios
我希望在我的UIViewController中有一个透明的背景,因为我使用了clearColor
colorPickerVc.view.backgroundColor = UIColor.clearColor()
presentViewController(colorPickerVc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
问题是当colorPickerVc完成加载时,背景颜色变黑了我想要一个解决方案,如果可能的话,在ios 7上工作,谢谢你的帮助
@ good4pc的解决方案:
colorPickerVc.view.backgroundColor = UIColor.clearColor()
if #available(iOS 8.0, *)
{
colorPickerVc.modalPresentationStyle = UIModal PresentationStyle.OverCurrentContext
}
else
{
colorPickerVc.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
}
presentViewController(colorPickerVc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
为我工作,谢谢你们的帮助
ios ×7
objective-c ×2
cocoa-touch ×1
ios7 ×1
iphone ×1
storyboard ×1
swift ×1
transparency ×1
uiscrollview ×1
uiview ×1
xcode ×1