
У меня есть NotificationViewController, который был создан, когда я реализовал расширение содержимого уведомлений, а затем избавился от него. раскадровку, чтобы я мог программно создать представление. Однако у меня возникли проблемы с уменьшением высоты фактического push-уведомления, когда пользователь делает долгое нажатие. Я думал, что представление представляет собой само уведомление, но это не так? Мне удалось изменить высоту уведомления в раскадровке, но мне сложно сделать это программно. Любая помощь будет полезна!
import UIKit
import UserNotifications
import UserNotificationsUI
/// A View Controller that is activated when a push notification is pressed for a while.
class NotificationViewController: UIViewController, UNNotificationContentExtension {
/// The label that displays the title of the push notification
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = .black
label.backgroundColor = .green
label.textAlignment = .center
label.isHidden = false
label.frame = CGRect(x: 100, y: 0, width: 100, height: 100)
return label
}()
override func loadView() {
self.view = UIView(frame: .zero)
view.backgroundColor = .red
view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(titleLabel)
NSLayoutConstraint.activate([
view.heightAnchor.constraint(equalToConstant: 100),
view.widthAnchor.constraint(equalToConstant: 100 * 5),
])
}
func didReceive(_ notification: UNNotification) {
let content = notification.request.content
self.titeLabel.text = content.body
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... mmatically
Мобильная версия