小编Nik*_*ani的帖子

人脸ID评估流程无法正常运行

我正在尝试获取以下功能中的Face ID或Touch ID是否成功

func authenticate() -> Bool{

    let context = LAContext()
    var error: NSError?

    guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
        return false
    }
    var returnValue = false
    let reason = "Face ID authentication"
    context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) 
    {
        isAuthorized, error in
        guard isAuthorized == true else {
            return print(error)
        }
        returnValue = true
        print("success")
    }
    return returnValue        
}
Run Code Online (Sandbox Code Playgroud)

但是即使此代码成功执行,它也会跳过,returnValue = true稍后再传递,导致返回错误。为什么会这样?以及如何解决此代码以使其像预期的那样工作?

上面的代码来自此链接 ,以防万一此人正在观看,谢谢。

authentication ios touch-id swift face-id

6
推荐指数
1
解决办法
2074
查看次数

如何在表格中显示自定义页脚视图?

我创建了一个UIviewXib来在我的表格的页脚视图中显示它。页脚视图

import UIKit

/// This class is to display footer view in a settings table view
class FooterView: UIView {
    override func awakeFromNib() {
        super.awakeFromNib()
    }
}
Run Code Online (Sandbox Code Playgroud)

我将其显示如下:

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let view = FooterView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 140))
    return view
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 100
}
Run Code Online (Sandbox Code Playgroud)

这有什么问题?我无法看到页脚视图并tableview在行之间获得如此多的空间。

在此处输入图片说明

uitableview ios tablefooterview swift

2
推荐指数
1
解决办法
6542
查看次数

UICollectionView Rotation 旋转后布局不正确

我有一个 UICollectionView,它的宽度正好是 7 个单元格,中间没有填充。我通过添加没有中间或行间距的流布局并计算宽度来完成此操作,如下所示:

public func collectionView(
    _ collectionView: UICollectionView, 
    layout collectionViewLayout: UICollectionViewLayout, 
    sizeForItemAt indexPath: IndexPath
) -> CGSize {
    return CGSize(
        width: self.frame.width / CGFloat(7), 
        height: self.frame.height - headerHeight
    )
}
Run Code Online (Sandbox Code Playgroud)

这在我的 iPhone 应用程序中运行得非常好

在此输入图像描述

未启用旋转的地方。在 iPad 上,当处于纵向模式时,效果很好。

在此输入图像描述

旋转时,首先应用程序不会重绘,我尝试使Layout无效,但这并没有解决问题。我必须向下滚动,然后得到以下布局

在此输入图像描述

当我点击一个单元格时,它会重新绘制,但添加了填充,将第七个单元格向下推到另一行。

在此输入图像描述

我希望重新绘制单元格,以便当应用程序在分割视图中旋转或放大和缩小时,所有 7 个单元格都可以放在一行上。我应该如何正确处理这个问题?

rotation ios uicollectionview swift

2
推荐指数
1
解决办法
1748
查看次数

我怎样才能在swift 4中获得deviceToken?

我正在使用此代码获取设备令牌它在swift 3中工作但不在swift 4中工作请帮我解决它.


if #available(iOS 10.0, *) {
      let center = UNUserNotificationCenter.current()
      center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
          }
}
 func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

     let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
    print(deviceTokenString)
}

apple-push-notifications devicetoken ios swift

1
推荐指数
2
解决办法
2万
查看次数