当我从导航堆栈中弹出视图控制器时,弹出的导航控制器中的蓝色视图在离开屏幕时会出现延迟,并拖尾在视图控制器的其余部分后面,如视频所示:https : //vid.me /GbBG
这是什么原因,如何解决?
我正在使用以下代码向我的导航控制器添加一个右栏按钮viewDidLoad:
var b = UIBarButtonItem(
image: UIImage(named: "settings"),
style: .plain,
target: self,
action: #selector(sayHello(sender:))
)
self.navigationItem.rightBarButtonItem = b
Run Code Online (Sandbox Code Playgroud)
我的settingspng 文件是白色的,但是当我运行应用程序时,我看到的是默认blue颜色。不管怎样,我想把它改成红色。我该怎么做?
我试过这个:
let navigationBarAppearnce = UINavigationBar.appearance()
navigationBarAppearnce.tintColor = UIColor.red
Run Code Online (Sandbox Code Playgroud)
但它没有用。这样做的正确方法是什么?
uinavigationcontroller uibarbuttonitem uibarbuttonitemstyle ios swift
出于这个问题的目的,我展示了我的视图层次结构的精简版本。我的应用程序包含一个UITabBarController作为基础。每个选项卡最顶部的视图控制器是一个导航控制器,并且每个视图控制器都嵌入了视图控制器。
让我们拿第一个标签。
UITabBarController -> UINavigationController -> UITableViewController -> UIViewController
假设UITableViewController实例是某种列表,而UIViewController是详细视图。当用户点击列表中的项目时,它会将您带到详细信息视图。当发生这种情况时,我已将UIViewController'shidesBottomBarWhenPushed属性设置为,true以便当用户处于详细视图时底部的标签栏将隐藏。
我的应用程序接收推送通知。当点击它们时,它应该直接打开到详细视图。我可以让它在那里导航。但问题是底部的标签栏仍然可见!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
if openingFromPush {
let firstNavigationController = storyboard.instantiateViewController(withIdentifier: "FirstNavigationController") as! UINavigationController
let tableViewController = storyboard.instantiateViewController(withIdentifier: "TableViewController") as! TableViewController
let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
viewController.hidesBottomBarWhenPushed = true
firstNavigationController.viewControllers …Run Code Online (Sandbox Code Playgroud) uitabbarcontroller uiviewcontroller uinavigationcontroller ios swift
我刚刚指出:
func animateTransition(transitionContext: UIViewControllerContextTransitioning)
Run Code Online (Sandbox Code Playgroud)
不叫 id 我推我的UIViewController:
navigationController?.pushViewController(nextVC, animated: true)
Run Code Online (Sandbox Code Playgroud)
否则,如果我展示我的UIViewController:
navigationController?.presentViewController(nextVC, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我的动画有效是因为 animateTransition 被调用
编辑:
它的用法如下:
let transitionManager = TransitionManager()
nextVC.transitioningDelegate = transitionManager
navigationController?.pushViewController(nextVC, animated: true)
Run Code Online (Sandbox Code Playgroud)
完整的动画类是:
class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {
private var presenting = true
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let container = transitionContext.containerView()
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
let offScreenRight = CGAffineTransformMakeTranslation(container!.frame.width, 0)
let offScreenLeft = CGAffineTransformMakeTranslation(-container!.frame.width, 0)
toView.transform = offScreenRight
container!.addSubview(toView)
container!.addSubview(fromView)
let duration …Run Code Online (Sandbox Code Playgroud) 我试图更改导航控制器后退按钮的字体大小,但无济于事。
我目前正在以前的视图控制器中执行此操作viewWillAppear:
navigationController?.navigationBar.backItem?.backBarButtonItem?.setTitleTextAttributes(
[NSAttributedStringKey.font : UIFont.systemFont(ofSize: 5)], for: .normal)
Run Code Online (Sandbox Code Playgroud)
上面的代码什么也没做。所以,有两个问题。
首先,更改后退按钮字体大小的正确方法是什么(顺便说一句,这似乎比应有的要困难得多)。
其次,是否有一个单一的地方(如 AppDelegate)我可以进行此更改,以便它影响所有视图控制器?
我 在项目中使用滑动菜单控制器窗格,但遇到了一些问题。当导航堆栈中有控制器并且我想向左滑动时,会出现汉堡菜单,而不是弹出控制器。这怎么能改变呢?有人可以指导我吗?
所以我知道这是一个非常基本的功能,您可以免费获得,但它在这里被覆盖。
我尝试关闭幻灯片菜单的平移手势,但它关闭了整个机制。
SlideMenuOptions.panGesturesEnabled = false
我也找到了handleLeftPanGesture(_ panGesture: UIPanGestureRecognizer)方法,如下所示:
open func isTargetViewController() -> Bool {
// Function to determine the target ViewController
// Please to override it if necessary
guard let navController = navigationController else { return true }
return navController.viewControllers.isEmpty
}
@objc func handleLeftPanGesture(_ panGesture: UIPanGestureRecognizer) {
if !isTargetViewController() {
navigationController?.popViewController(animated: true)
}
if isRightOpen() {
return
}
switch panGesture.state {
case UIGestureRecognizerState.began:
if LeftPanState.lastState != .ended && LeftPanState.lastState != .cancelled && LeftPanState.lastState != …Run Code Online (Sandbox Code Playgroud) 我以编程方式构建了一个 UICollectionViewController,它返回 4 个单元格。HomeCell、TrendingCell、SubscriptionCell 和 AccountCell。所有 4 个单元格应该不同,您可以水平滚动它们。<--->。
class HomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout{
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.register(HomeCell.self, forCellWithReuseIdentifier: homeCellId)
collectionView?.register(TrendingCell.self, forCellWithReuseIdentifier: trendingCellId)
collectionView?.register(SubscriptionCell.self, forCellWithReuseIdentifier: subscriptionCellId)
collectionView?.register(AccountCell.self, forCellWithReuseIdentifier: accountCellId)
}
}Run Code Online (Sandbox Code Playgroud)
让我们以 HomeController 的第一个单元(称为 HomeCell)来说明我的问题。Homecell 具有三个自定义单元,称为 VideoCell、CategoryCell 和 UserSearchCell。
class HomeCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
let cellId = "cellId"
let searchId = "sarchId"
let scrollId = "scrollId"
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.white
cv.dataSource = …Run Code Online (Sandbox Code Playgroud)uinavigationcontroller ios uicollectionviewcell uicollectionviewdelegate swift
我正在开发一个项目,我以下面的方式调用其他viewcontroller: -
AppDelegate *app2 = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[self.navigationController pushViewController:app2.SecondForm animated:NO];
app2 =nil;
Run Code Online (Sandbox Code Playgroud)
我的应用程序是基于导航的,我在导航栏上创建了我的后退按钮
-(void)viewDidLoad
{
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarStyleBlackOpaque target:self action:@selector(Back:)];
}
Run Code Online (Sandbox Code Playgroud)
通过这种方式我的后退动作将调用点击
-(IBAction)Back:(id)sender
{
// What code I will write over here to get the same functionality
// which is by default given by navigation controller?
}
Run Code Online (Sandbox Code Playgroud) 如何在app delegate中添加UINavigationController&以UITabBarController编程方式.
objective-c uitabbarcontroller uinavigationcontroller ios appdelegate