使用多任务在iPad上测试我的应用程序时,如果我更改了应用程序的大小,则需要调整集合视图单元格的大小,否则它们将不适合视图窗口。
我已经采取了一些措施,例如
一切都很好,但是当使用多任务处理或实际返回到全屏应用程序时实际更改窗口大小时,单元格大小不会改变并且看起来很不合适。直到通过切换方向或切换视图控制器强制这样做viewWillLoad或viewDidLoad再次执行。
那么,如果view.frame大小发生变化,如何设置通知?
我有一个UISplitViewController具有以下布局,由单个主视图和详细视图控制器组成.
这适用于具有单个视图的基本拆分视图,但我需要支持UITableViewController(主视图)中的多个segue,并且在数据传递之前不加载细节视图; 否则应用程序会因可选错误而崩溃.
我尝试过像这样的设置;
这会ViewController在UISplitViewController加载时加载一个空白作为详细视图,当选择一行时,我有一个细节segue到其他视图控制器,它应该显示为详细视图UISplitViewController.
遗憾的是,这并不完全正常,所有数据都是在没有崩溃的情况下传递和加载的,但细节segues实际上是在分割视图的主视图窗口中加载视图控制器而不是详细视图.
有点像这样,
如何在从主视图启动segue UITableViewController并在详细信息窗口中打开之前,是否有多个未加载的详细视图控制器?
这是MasterViewController的代码
override func viewDidLoad() {
super.viewDidLoad()
self.splitViewController!.delegate = self;
self.splitViewController!.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
self.extendedLayoutIncludesOpaqueBars = true
}
func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 [MarkdownTextView][1] 将基本降价添加到UITextView. 该TextView是的子类MarkdownTextView。
但是,当使用复制和粘贴时,我收到以下错误
致命错误:对 MarkdownTextStorage 类使用未实现的初始化程序“init()”
这就是我在 ViewController 中使用 TextStorage 的方式
let fonty = UIFont(name: font, size: fsize)
attributes.defaultAttributes[NSFontAttributeName] = fonty
attributes.orderedListAttributes?[NSFontAttributeName] = fonty
attributes.orderedListItemAttributes?[NSFontAttributeName] = fonty
attributes.unorderedListAttributes?[NSFontAttributeName] = fonty
attributes.unorderedListItemAttributes?[NSFontAttributeName] = fonty
let textStorage = MarkdownTextStorage(attributes: attributes)
do {
textStorage.addHighlighter(try LinkHighlighter())
} catch let error {
fatalError("Error initializing LinkHighlighter: \(error)")
}
textStorage.addHighlighter(MarkdownStrikethroughHighlighter())
textStorage.addHighlighter(MarkdownSuperscriptHighlighter())
if let codeBlockAttributes = attributes.codeBlockAttributes {
textStorage.addHighlighter(MarkdownFencedCodeHighlighter(attributes: codeBlockAttributes))
}
Run Code Online (Sandbox Code Playgroud)
我使用了以下初始化程序,但仍然没有运气
required public init?(coder aDecoder: NSCoder) {
attributes = …Run Code Online (Sandbox Code Playgroud) 所以我已经成功地将几乎所有项目转换为Swift 3,除了从一个View Controller中我手动添加约束.
我得错了
view.addSubview(textView)
textView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(textView)
let views = ["textView": textView]
var constraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-70-[textView]-8-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-8-[textView]-8-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
NSLayoutConstraint.activate(constraints)
Run Code Online (Sandbox Code Playgroud)
所以我改成了
textView.translatesAutoresizingMaskIntoConstraints = true
view.addSubview(textView)
textView.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
textView.autoresizingMask = [UIViewAutoresizing.flexibleLeftMargin, UIViewAutoresizing.flexibleRightMargin, UIViewAutoresizing.flexibleTopMargin, UIViewAutoresizing.flexibleBottomMargin]
Run Code Online (Sandbox Code Playgroud)
我想要做的就是在视图控制器中添加一个UITextViewa UIView,它占据整个高度和宽度,并在中心垂直和水平.我明显错过了我的更新代码,并且不确定为什么我之前的代码拒绝运行,因为我在Swift 2.2中工作.
任何人都可以回答在Swift 3中添加约束的正确方法吗?
更新:
这是我的原始代码转换为Swift 3.0的错误
2016-09-06 22:08:38.751636 APPNAME [570:65129] - [_ SwiftValue nsli_superitem]:无法识别的选择器发送到实例0x17044a0e0 2016-09-06 22:08:38.752963 APPNAME [570:65129] *终止应用程序由于未被捕获异常'NSInvalidArgumentException',原因是: ' …
所以我一直在尝试实现iOS 10 Local Notifications,首先我认为代码与iOS 9相同,只是添加了一个通知扩展目标.然而它实际上使用了这个UNMutableNotificationContent类,
我可以使用时间间隔设置通知,但是如何使用日期选择器专门设置开火日期?
import UserNotifications
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full
let displayDate = dateFormatter.string(from: datePicker.date)
let notif = UNMutableNotificationContent()
notif.title = "Reminder)"
notif.subtitle = "\(displayDate)"
notif.body = "Details"
notif.categoryIdentifier = "Details Reminder"
let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "myNotif", content: notif, trigger: notifTrigger)
Run Code Online (Sandbox Code Playgroud)
该 UNNotificationRequest触发需要的类型UNTimeIntervalNotificationTrigger,我希望我可以只添加一个日期.
我是否需要使用当前日期和日期选择日期来计算间隔时间?或者我可以通过其他方式做到这一点