热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

导航栏中的后退按钮未在ios11中轻触-Backbuttoninnavigationbarnotgettingtappedinios11

ItwasworkingfineuntiltherecentupdatewhereithinkthenavigationitemshouldworkwiththeA

It was working fine until the recent update where i think the navigation item should work with the AutoLayout concept. I have been using it like this:

它工作正常,直到最近的更新,我认为导航项应该与AutoLayout概念一起使用。我一直在使用它:

let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: 30, height: 30)))
button.setImage(UIImage(named: "BackIcon"), for: UIControlState())
button.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0)
button.addTarget((target != nil ? target! : self), action: backAction, for: .touchUpInside)
navigationItem.leftBarButtOnItem= UIBarButtonItem(customView: button)

what changes i should do to make it smooth cause at the moment it doesn't gets called on every tap, usually it's taking 2-3 times to get tapped in the same region.

我应该做些什么改变才能使它平滑,因为它不会在每次敲击时被调用,通常需要2-3次才能在同一区域内进行调整。

4 个解决方案

#1


0  

This worked for me on iOS 11. Check out and see if it works for you.

这在iOS 11上适用于我。退房并查看它是否适合您。

    let btnLeftMenu = UIButton.init(type: .system)
    let image = UIImage(named: "Back");
    btnLeftMenu.setImage(image, for: .normal)
    btnLeftMenu.setTitle("BACK", for: .normal);
    btnLeftMenu.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0)
    btnLeftMenu.titleEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0)
    btnLeftMenu.sizeToFit()
    btnLeftMenu.tintColor = UIColor.white
    btnLeftMenu.titleLabel?.fOnt= UIFont.init(name: "Avenir-Heavy", size: 16.0)
    btnLeftMenu.addTarget(self, action: #selector (CustomMessageVC.backButtonAction(_:)), for: .touchUpInside)
    let barButton = UIBarButtonItem(customView: btnLeftMenu)
    self.navigationItem.leftBarButtOnItem= barButton

[EDIT]

Probably the width and height of the image are small. You can check the backbutton width and height using realtime Viewstack on Xcode debug. Click on 2nd button from right in the image to see the ViewStack. if width and height are the issues then increase the button width and height with image being centred and imageView property to aspect fit. that should solve your problem. Happy coding.

可能图像的宽度和高度很小。您可以使用Xcode调试上的实时Viewstack检查后退按钮的宽度和高度。单击图像右侧的第二个按钮以查看ViewStack。如果宽度和高度是问题,那么增加按钮的宽度和高度,图像居中,imageView属性适合宽高比。这应该可以解决你的问题。快乐的编码。

Image

#2


0  

Works for me:

适合我:

let backButton = UIBarButtonItem(title: "Back",
            style: .done,
            target: self,
            action: #selector(moveBack))
navigationItem.setLeftBarButton(backButton, animated: false)

Open view debugger and check frame for leftBarButtonItem. You should be careful with leftBarButton, because it doesn't inherit from UIView and generate frame in runtime.

打开视图调试器并检查leftBarButtonItem的框架。你应该小心使用leftBarButton,因为它不会从UIView继承并在运行时生成帧。

#3


0  

Found this trouble lurking in our app as well now that iOS 11 is out, so here's my solution. It's not perfect as you do need to set the frame for the buttons, but gets the job done, and works on iOS 9.3/10.3.1/11.1 (and probably in between). Tap area is normal and UX is good.

现在iOS 11已经出现,我们的应用程序中发现了这个问题,所以这是我的解决方案。它并不完美,因为你需要设置按钮的框架,但完成工作,并在iOS 9.3 / 10.3.1 / 11.1(可能在其间)工作。 Tap区域正常,UX很好。

Before: ios11 button bounds before adjusting frame

After: tap area expanded

I call this in viewDidLoad:

我在viewDidLoad中调用它:

func setNavbarButtons() {
    // setup the left and right nav bar buttons

    // manually define the frame for the buttons
    let buttonWidth: CGFloat  = 44
    var buttonHeight: CGFloat = buttonWidth

    // if possible, use the nav bar height as the button height, else fall back to the manual value above
    if let frame = self.navigationController?.navigationBar.frame {
        buttOnHeight= frame.height
    }

    // apply this to the left inset for the left button, right inset for the right button, so the image is pushed to the left/right respectively
    // (hence the negative value)
    // setting this to 0 will center the image in the button and we don't want that
    let edgeInset = -(buttonWidth/2)

    // setup a button to hold the image (left)
    let leftButton = UIButton(type: .custom)
    let backIcon = UIImage(named: "Back with shadow")
    backIcon!.isAccessibilityElement = true
    backIcon!.accessibilityLabel = "Back"

    // no title text
    leftButton.setTitle("", for: .normal)
    leftButton.setImage(backIcon, for: .normal)
    leftButton.sizeToFit()
    leftButton.addTarget(self, action: #selector(self.didTapLeftNavbarButton), for: .touchUpInside)

    // define left button frame and inset
    leftButton.frame.size.width = buttonWidth
    leftButton.frame.size.height = buttonHeight
    leftButton.cOntentEdgeInsets= UIEdgeInsetsMake(0, edgeInset, 0, 0)

    // finally setup a UIBarButtonItem to hold the UIButton (arg)
    let leftBarButtOnItem= UIBarButtonItem(customView: leftButton)
    leftBarButtonItem.title = ""

    // set it
    self.navigationItem.setLeftBarButton(leftBarButtonItem, animated: true)

    // rinse/wash/repeat for right button
    let rightButton = UIButton(type: .custom)
    let shareIcon = UIImage(named: "Share")
    shareIcon!.isAccessibilityElement = true
    shareIcon!.accessibilityLabel = "Share"

    // no title text
    rightButton.setTitle("", for: .normal)
    rightButton.setImage(shareIcon, for: .normal)
    rightButton.sizeToFit()
    rightButton.addTarget(self, action: #selector(self.didTapActionButton(_:)), for: .touchUpInside)

    // define right button frame and inset
    rightButton.frame.size.width = buttonWidth
    rightButton.frame.size.height = buttonHeight
    rightButton.cOntentEdgeInsets= UIEdgeInsetsMake(0, 0, 0, edgeInset)

    let rightBarButtOnItem= UIBarButtonItem(customView: rightButton)
    rightBarButtonItem.title = ""

    self.navigationItem.setRightBarButton(rightBarButtonItem, animated: true)
}

#4


0  

Overriding the following method in my custom UIView class did the trick for me:

在我的自定义UIView类中覆盖以下方法对我来说是个窍门:

override var intrinsicContentSize: CGSize {
        return UILayoutFittingExpandedSize
    }

推荐阅读
  • 本文介绍如何在 Android 中通过代码模拟用户的点击和滑动操作,包括参数说明、事件生成及处理逻辑。详细解析了视图(View)对象、坐标偏移量以及不同类型的滑动方式。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 本文介绍如何使用 NSTimer 实现倒计时功能,详细讲解了初始化方法、参数配置以及具体实现步骤。通过示例代码展示如何创建和管理定时器,确保在指定时间间隔内执行特定任务。 ... [详细]
  • 本文详细介绍了macOS系统的核心组件,包括如何管理其安全特性——系统完整性保护(SIP),并探讨了不同版本的更新亮点。对于使用macOS系统的用户来说,了解这些信息有助于更好地管理和优化系统性能。 ... [详细]
  • 本文详细探讨了KMP算法中next数组的构建及其应用,重点分析了未改良和改良后的next数组在字符串匹配中的作用。通过具体实例和代码实现,帮助读者更好地理解KMP算法的核心原理。 ... [详细]
  • 本文详细介绍了 GWT 中 PopupPanel 类的 onKeyDownPreview 方法,提供了多个代码示例及应用场景,帮助开发者更好地理解和使用该方法。 ... [详细]
  • 深入理解 Oracle 存储函数:计算员工年收入
    本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • C++: 实现基于类的四面体体积计算
    本文介绍如何使用C++编程语言,通过定义类和方法来计算由四个三维坐标点构成的四面体体积。文中详细解释了四面体体积的数学公式,并提供了两种不同的实现方式。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
author-avatar
无奈的双子星_403
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有