Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 开发小结 #3

Open
aTreey opened this issue Jun 4, 2018 · 0 comments
Open

iOS 开发小结 #3

aTreey opened this issue Jun 4, 2018 · 0 comments
Labels
iOS知识小结 This doesn't seem right

Comments

@aTreey
Copy link
Owner

aTreey commented Jun 4, 2018

Swift4.1 中UIImagebase64转化

  • 使用 public init?(base64Encoded base64String: String, options: Data.Base64DecodingOptions = default)函数

官方解释
Initialize a Data from a Base-64 encoded String using the given options.
Returns nil when the input is not recognized as valid Base-64.
- parameter base64String: The string to parse.
- parameter options: Encoding options. Default value is [].

默认是 options 是 [] 项目中为设置 options 时返回的data 值为nil,无法生成图片

  • 需要设置 options 为 .ignoreUnknownCharacters 即可,作用是忽略未知的非基64字节,每行结束字符
let imageData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters)
 if let data = imageData {
    let image = UIImage(data: data)
    imageView.image = image
  }

Swift4.1 中获取类名及通过类名生成对象

获取类名

 let clsName = String(describing: controller.classForCoder)
 let dyName = type(of: controller) 
 print("clsName=\(clsName)") 
 print("dyName = \(dyName)")
 print(controller.description) 
 print(controller.classForCoder.description())
 print(String(controller.description))
print(type(of:controller))
print(String(describing: type(of:controller))) print(NSStringFromClass(type(of:controller)).components(separatedBy: ".").last!)

结果

tableView cell 上添加ScrollView后tableViewcell不响应点击事件处理

scrollView.userInteractionEnabled = false;
[self.contentView addGestureRecognizer:scrollView.panGestureRecognizer];

事件传递、响应者链条、hitTest和pointInside的使用

  • hitTest: 返回的是最适合处理事件的View
  • pointInside:判断事件发生的位置是否处于当前视图范围内
    只有pointInside返回Yes的处理事件的view才能真正响应点击事件

使用UISearchBar 底部有时会出现1像素的黑线解决办法

if (@available(iOS 11.0, *)) {
         [[self.searchBar.heightAnchor constraintEqualToConstant:44.0] setActive:YES];
     }
self.searchDisplayController.searchBar.barStyle = UISearchBarStyleProminent

swift 和 OC 混编 Podfile 中使用use_frameworks! 相关问题

使用 use_frameworks!关键词后 头文件导入时直接使用 @import XXX; 这样更加方便效率也更高

项目中颜色图片统一管理

  • swift 项目中给UIColor 添加分类
  • xcode 9 中的 Color Set 方式设置(iOS 11 以上才可以使用)
  • 使用第三方库
    R.swift
 myImageView.image = #imageLiteral(resourceName: "icon_cat")
 myImageView.image = R.image.icon_cat()

sizeToFit 和 sizeThatFits 区别

@aTreey aTreey added the iOS知识小结 This doesn't seem right label Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS知识小结 This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant