我有一个侧面导航控制器,并通过UIButton呈现它.当我直接将这个NC作为根视图控制器时[self presentviewcontroller: NC animated: YES completion: nil],某些原因NC的菜单面被一个UITransitionView我无法消失的东西阻挡.
我尝试过以下方法:
UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
window.backgroundColor = kmain;
CATransition* transition = [CATransition animation];
transition.duration = .5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[nc.view.layer addAnimation:transition forKey:kCATransition];
[UIView transitionWithView:window
duration:0.5
options:UIViewAnimationOptionTransitionNone
animations:^{ window.rootViewController = nc; }
completion:^(BOOL finished) {
for (UIView *subview in window.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UITransitionView")]) {
[subview removeFromSuperview];
}
}
}];
Run Code Online (Sandbox Code Playgroud)
但它非常hacky,并且随着窗口的rootviewcontroller在转换过程中发生变化,它会有点波动,导航控制器的一部分和右上角变黑.看起来很糟糕.
uiviewcontroller uinavigationcontroller catransition uiviewanimationtransition ios
我有一个从底部UIViewController只UIView覆盖viewController的1/3.像这样
我想在另一个ViewController上呈现这个viewController.它应该从底部动画出现,它应该忽略到底部动画.
但我不希望它覆盖整个屏幕.显示它的viewController应该在后面可见.
这似乎是一个基本问题但我无法完成它.有人可以指点我的方向吗?
编辑:
这就是我迄今为止所尝试过的.我创建了这些类
// MARK: -
class MyFadeInFadeOutTransitioning: NSObject, UIViewControllerTransitioningDelegate {
var backgroundColorAlpha: CGFloat = 0.5
var shoulDismiss = false
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fadeInPresentAnimationController = MyFadeInPresentAnimationController()
fadeInPresentAnimationController.backgroundColorAlpha = backgroundColorAlpha
return fadeInPresentAnimationController
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let fadeOutDismissAnimationController = MyFadeOutDismissAnimationController()
return fadeOutDismissAnimationController
}
}
// MARK: -
class MYFadeInPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
let kPresentationDuration = 0.5
var backgroundColorAlpha: CGFloat?
func transitionDuration(using …Run Code Online (Sandbox Code Playgroud) 问题
不调用'DrinkTransitioningDelegate'中的委托函数.'td'实例在演示文稿的生命周期内和之外保留在内存中.
class PresentingViewController: UIViewController {
let td = DrinkTransitioningDelegate()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let item = inventory.beverages[indexPath.row]
item.isSelected = true
let controller = DrinkViewController(item: item)
controller.delegate = self
controller.transitioningDelegate = td
controller.modalPresentationStyle = .custom
//let navCon = UINavigationController(rootViewController: controller)
//navCon.transitioningDelegate = td
//navCon.modalPresentationStyle = .custom
present(controller, animated: true)
}
}
class DrinkTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? {
return DrinkPresentationViewController(presentedViewController:presented, presenting: presenting)
}
let animationController = …Run Code Online (Sandbox Code Playgroud) 我想要 pageSheet UIModalPresentationStyle segue 的所有功能,但我只希望呈现的 ViewController 显示一半屏幕(请参见下图中的示例)。
我使用 pageSheet modalPresentationStyle 以模态方式呈现它,但它始终以 100% 高度呈现。
我一直无法弄清楚如何限制或修改 ViewController 的高度。我在 SecondViewController 中尝试了以下操作,但没有成功:
import UIKit
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.preferredContentSize = CGSize(width: self.view.frame.width, height: 400)
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个视图,我想显示一个自定义大小的UIViewController.但我没有成功.这是我的代码.
var vx = KeyboardViewController()
vx.modalPresentationStyle = UIModalPresentationStyle.FormSheet
vx.preferredContentSize = CGSizeMake(self.view.frame.width, 150)
self.presentViewController(vx, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
此UIViewController以全屏大小显示