小编Chr*_*ris的帖子

Xcode 15 不反映故事板中使用的字体

我将 Xcode 更新到版本 15。

我的问题是,当我在 iOS 设备和模拟器上运行应用程序时,我通过故事板设置的字体没有正确反映。有谁知道为什么?

我知道解决方法是以编程方式设置字体,正如我发现苹果在其发行说明中所描述的那样,但我真的希望避免这种情况,如果碰巧存在一个不那么繁琐的解决方案!

xcode fonts storyboard ios

14
推荐指数
1
解决办法
2243
查看次数

FIrebase Firestore onCreate Cloud功能事件参数未定义

我已尝试按照Firebase的文档和其他SO帖子访问我已成功部署的云功能的参数值.

不幸的是我还在收到一个

类型错误:无法读取未定义的属性"id"

我已经记录了event.params,它输出为未定义,所以我理解了这个问题,但我不确定在语法上,我应该如何推导出param值.

以下是我的js代码供参考:

exports.observeCreate = functions.firestore.document('/pathOne/{id}/pathTwo/{anotherId}').onCreate(event => {
  console.log(event.params);

  //event prints out data but params undefined...
  const data = event.data()

  var id = event.params.id;

  return admin.firestore().collection('path').doc(id).get().then(doc => {
    const data = doc.data();
    var fcmToken = data.fcmToken;

    var message = {
      notification: {
        title: "x",
        body: "x"
      },
      token: fcmToken
    };

    admin.messaging().send(message)
      .then((response) => {
        console.log('Successfully sent message:', response);
        return;
      })
      .catch((error) => {
        console.log('Error sending message:', error);
        return;
      });

      return;
  })
})
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-functions google-cloud-firestore

4
推荐指数
1
解决办法
4380
查看次数

为 iOS 的 FCM 推送通知启用默认声音

我正在尝试为发送的推送通知设置默认声音,并让以下消息对象通过。

var message = {
      notification: {
        title: "X",
        body: "X",
        sound: 'default'
      }          
      token: fcmToken
 };
Run Code Online (Sandbox Code Playgroud)

但是,我继续在云函数日志中收到以下错误:

发送消息时出错:错误:收到无效的 JSON 负载。“message.notification”中的未知名称“声音”:找不到字段。

我尝试将声音属性放在通知对象 apns-payload-aps 对象下,但似乎无法找到有关激活 iOS 上默认声音的正确语法的文档。

任何帮助表示赞赏。

push-notification ios firebase google-cloud-functions firebase-cloud-messaging

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

使用Lottie自定义UIRefreshControl

我的目标是UIRefreshControl用Lottie动画替换默认的微调框。

我的问题是,当我下拉UICollectionView子视图为的子视图时,动画无法立即播放UIRefreshControl。仅当我稍微向下滚动并暂停手指时,动画才会播放。当我再次开始移动滚动位置时,它立即返回到其初始播放状态,不再播放。

任何指导将不胜感激,以下是相关代码。

func setupRefreshControl() {
    guard let refreshContents = Bundle.main.loadNibNamed("RefreshControlView", owner: self, options: nil), let refreshView = refreshContents[0] as? RefreshControlView else { return }

    refreshView.frame = refreshControl.frame
    refreshControl.addSubview(refreshView)

    refreshControl.tintColor = UIColor.clear
    refreshControl.backgroundColor = UIColor.clear
    refreshControl.addTarget(self, action: #selector(exampleFunction), for: .valueChanged)      
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    for subview in refreshControl.subviews {
        if let refreshControlView = subview as? RefreshControlView {
            refreshControlView.activityIndicatorControl.animationView.setAnimation(named: "lottieJson")                
            refreshControlView.activityIndicatorControl.animationView.loopAnimation = true
            refreshControlView.activityIndicatorControl.animationView.play()
            break
        } else {
            continue
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uirefreshcontrol swift lottie

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

PromiseKit For In 循环实现时

使用Swift,我PromiseKit第一次尝试将 Promise 合并到我的代码中,并且在语法上难以理解如何使其工作。

我的目标是将Firebase数据请求流水线化,并在所有返回的数据满足附加数组后执行另一种方法。似乎promise已解决并在使用数据设置数组之前运行最终方法。我相信我应该使用“when”,但不可否认的是理解文档有困难。

缩写,相关代码如下:

getPosts(ids).done {
    runningFinalMethod(self.arr)
}

func getPosts(_ ids: [String]) -> Promise<Void>  {
    return Promise { seal in
        for id in ids {
            db.collection("data").whereField("id", isEqualTo: id).getDocuments(completion: { (dataForId, error) in                
                appendData(dataForId)
            })
        }
        seal.fulfill(())
    }
}

func appendData(_ dataForId: [data]) {                                  
    arr.append(contentsOf: dataForId)            
}
Run Code Online (Sandbox Code Playgroud)

promise ios firebase swift promisekit

0
推荐指数
1
解决办法
1265
查看次数

Toggle 在最大行数后启用 UITextView 滚动

uitextview subview在 inputContainerView 中有一个,因为它可能出现在消息传递应用程序中。

以编程方式,在加载uitextview时,初始化 inputContainerView 时设置的高度锚点。当输入更多行文本时,此约束在增加容器高度方面非常有效。

我的目标是uitextview在达到 X 行之后限制其高度,此后键入的任何行都可以滚动。同样,当行数低于最大值时,它会返回到其原始形式 - 不可滚动并根据内容自动调整高度。

经过多次试验和研究,一旦达到最大行数,我就设法获得了注视的高度,但是一旦行数低于最大值,我似乎无法弄清楚如何将其恢复到原始形式。看起来uitextview高度停留在行数达到最大值的高度。

下面是相关代码:

//Container View Initialization, onLoad Frame Height is set to 60
override init(frame: CGRect) {
super.init(frame: frame)
autoresizingMask = .flexibleHeight

addSubview(chatTextView)
textView.heightAnchor.constraint(greaterThanOrEqualToConstant: frame.height - 20).isActive = true
}

//TextView Delegate

var isTextViewOverMaxHeight = false
var textViewMaxHeight: CGFloat = 0.0

func textViewDidChange(_ textView: UITextView) {
    let numberOfLines = textView.contentSize.height/(textView.font?.lineHeight)!

    if Int(numberOfLines) > 5 {

        if !isTextViewOverMaxHeight {
            containerView.textView.heightAnchor.constraint(greaterThanOrEqualToConstant: 40).isActive = …
Run Code Online (Sandbox Code Playgroud)

uitextview uitextviewdelegate ios nslayoutconstraint swift

0
推荐指数
1
解决办法
307
查看次数