美文网首页
小知识九、常见问题

小知识九、常见问题

作者: ISwiftUI | 来源:发表于2017-06-27 03:24 被阅读4次

【常见问题一】获取Assets.car中新特性图片的问题

在代码中常用获取获取的两种方法如下:


1.cell.imageView?.image = UIImage.init(contentsOfFile: imageUrl)
2.cell.imageView?.image = UIImage.init(named: "")

相信很多人都知道会出现什么问题了吧,我们知道一般新特性的图片一般都是比较的高清的,如果使用第二种方式加载就会出现图片缓存到内存中去。当我们遇到这种情况是往往会选择第一种加载图片的方式。那么如果我们使用第一种方式,应该怎么实现呢。

1.将较大的图片资源打包成bundle包


14985020808499.jpg

2.获取图片的路径


    fileprivate func getImageName(index: Int) -> String? {
        var imageNamePath: String?
        if let guide_imagesPath: String = Bundle.main.path(forResource: "guide_pageImages.bundle", ofType: "") {
            if let bundle: Bundle = Bundle.init(path: guide_imagesPath) {
                var fileName: String = images[index]
                fileName.append("@2x")
                if let imageURL: String = bundle.path(forResource: fileName, ofType: "png") {
                    imageNamePath = imageURL
                }
            }
        }
        return imageNamePath
    }
    

【常见问题二】cell 选择后present or push viewController有延迟

场景: 当设置cell.selectionStyle = UITableViewCellSelectionStyle.none,cell 选择后present or push viewController有延迟

解决方式:通过添加手势监听的方式解决

【常见问题三】NavigationBar的返回按钮不需要文字

解决办法一:


// 隐藏返回按钮的文字
let appearance = UIBarButtonItem.appearance()
appearance.setBackButtonTitlePositionAdjustment(UIOffset.init(horizontal: 0.0, vertical: -60), for: .default)

解决办法二:
自定义返回按钮。据我所知,很多人喜欢使用这种方式,在基类UINavigationController红重写push方法中自定义返回按钮,用来覆盖掉原来的leftBackItem.

相关文章

网友评论

      本文标题:小知识九、常见问题

      本文链接:https://www.haomeiwen.com/subject/opescxtx.html