我正在探索Xcode 11和macOS Catalina的新可能性,以使用UIKit创建Mac版本的iPad应用程序。通常按预期工作。
什么是最好的方式定制的NSWindow
在在MacOS iOS应用程序?
https://developer.apple.com/documentation/uikit/creating_a_mac_version_of_your_ipad_app
您可以使用相同的方法来包含仅在macOS中可用的框架和代码。对于框架,请选择macOS作为平台设置,并使用#if targetEnvironment(UIKitForMac)语句将代码括起来。
首先,我创建了一个基本的macOS框架(例如MacMan.framework
)来配置Mac特定的行为。
尽管尽了最大的努力,但我还是遇到了错误:
#if !targetEnvironment(UIKitForMac)
override var prefersHomeIndicatorAutoHidden: Bool {
return true
}
#endif
Run Code Online (Sandbox Code Playgroud)
参考文献:
https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit
UIKeyboardAppearanceDark
用SLComposeViewController
?该SLComposeViewController
班提出了以用户为撰写支持社交网络服务的一个职位.
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[self presentViewController:controller
animated:YES
completion:nil];
Run Code Online (Sandbox Code Playgroud)
丑陋!
这是浅色键盘在深色背景下的外观:
小样!
这是黑暗键盘在深色背景下的外观:
WKInterfaceMovie - 一个界面元素,可让您在watchOS应用程序中播放视频和音频内容.
按预期工作.视频播放.如何缩放它以填满屏幕?
func setVideoGravity(_ videoGravity: WKVideoGravity)
电影的大小调整选项.有关可能值的列表,请参阅WKVideoGravity类型.
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var movieView: WKInterfaceMovie!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
setupVideoPlayer()
}
func setupVideoPlayer() {
guard let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") else {
return
}
movieView.setMovieURL(videoURL)
movieView.setVideoGravity(.resizeAspectFill)
}
}
Run Code Online (Sandbox Code Playgroud)
Xcode中的基本设置.轻触播放按钮时视频加载.加载后播放.不填充屏幕.
WKVideoGravity
表示视频内容外观的常量.
case resizeAspectFill
Run Code Online (Sandbox Code Playgroud)
调整内容的大小以完全填充边界矩形,同时保留内容的原始宽高比.此选项会导致视频边缘超出其裁剪范围.
那很完美.我们来试试吧.
它不起作用.
无论videoGravity
(在故事板或代码中),视频播放都会调整大小以适应,只有在我点按两次时才会填满屏幕.
我错过了什么?
另外,如果我presentMediaPlayerController
使用Media Player Options 探索该方法,我会注意到一种奇怪的行为:
• WKMediaPlayerControllerOptionsAutoplayKey
✅
• …
回应听写的已知方法:
dictationRecordingDidEnd - 响应完成对口述短语的识别.
dictationRecognitionFailed - 响应失败的听写识别.
参考: UITextInput协议参考
从iOS 5.1开始,当用户在支持的设备上选择听写输入时,系统会自动将识别的短语插入当前文本视图中.UITextInput协议中的方法允许您的应用程序响应完成听写,如"使用听写"中所述.您可以使用UIDictationPhrase类的对象来获取表示用户已指定的短语的字符串.在不明确的听写结果的情况下,听写短语对象提供包含替代字符串的数组.
你如何映射AFIncrementalStore
到Twitter API v1.1?
AFNetworking的核心数据持久性,完成正确
https://github.com/AFNetworking/AFIncrementalStore
REST API v1.1资源
https://dev.twitter.com/docs/api/1.1
- (id)representationOrArrayOfRepresentationsOfEntity:(NSEntityDescription *)entity
fromResponseObject:(id)responseObject;
- (NSDictionary *)representationsForRelationshipsFromRepresentation:(NSDictionary *)representation
ofEntity:(NSEntityDescription *)entity
fromResponse:(NSHTTPURLResponse *)response;
- (NSString *)resourceIdentifierForRepresentation:(NSDictionary *)representation
ofEntity:(NSEntityDescription *)entity
fromResponse:(NSHTTPURLResponse *)response;
- (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
ofEntity:(NSEntityDescription *)entity
fromResponse:(NSHTTPURLResponse *)response;
- (NSMutableURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest
withContext:(NSManagedObjectContext *)context;
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
pathForObjectWithID:(NSManagedObjectID *)objectID
withContext:(NSManagedObjectContext *)context;
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
pathForRelationship:(NSRelationshipDescription *)relationship
forObjectWithID:(NSManagedObjectID *)objectID
withContext:(NSManagedObjectContext *)context;
Run Code Online (Sandbox Code Playgroud) NSTableView 带有附加的 NSMenu。
右键单击表视图后,将出现菜单。有了它,表视图将突出显示带有彩色边框的行。
使用Mac 开发人员库中的HoverTableDemo作为参考点。
默认颜色对应于“系统偏好设置”->“常规”->“突出显示颜色”中的用户首选项。
OS X Yosemite推出了NSStoryboardSegue
"故事板segue指定故事板中两个场景之间的过渡或遏制关系......"
更新:
•如果我尝试在带有Yosemite的Storyboard中使用NSStoryboardSegue子类,则它会与SIGABRT崩溃.
•如果我忽略segues,并使用指定的自定义动画师手动呈现视图控制器以进行演示和解雇,
func presentViewController(_ viewController: NSViewController,
animator animator: NSViewControllerPresentationAnimator)
Run Code Online (Sandbox Code Playgroud)
它按预期工作.
这篇文章提供了额外的见解:在OS X Yosemite中为ViewController定制动画
使用它作为参考,这是我到目前为止的尝试:
class FadeSegue: NSStoryboardSegue {
override func perform() {
super.perform()
sourceController.presentViewController(destinationController as NSViewController,
animator: FadeTransitionAnimator())
}
}
class FadeTransitionAnimator: NSObject, NSViewControllerPresentationAnimator {
func animatePresentationOfViewController(toViewController: NSViewController, fromViewController: NSViewController) {
toViewController.view.wantsLayer = true
toViewController.view.layerContentsRedrawPolicy = .OnSetNeedsDisplay
toViewController.view.alphaValue = 0
fromViewController.view.addSubview(toViewController.view)
toViewController.view.frame = fromViewController.view.frame
NSAnimationContext.runAnimationGroup({ context in
context.duration = 2
toViewController.view.animator().alphaValue = 1
}, completionHandler: nil)
}
func animateDismissalOfViewController(viewController: NSViewController, fromViewController: NSViewController) { …
Run Code Online (Sandbox Code Playgroud) let colorArray = [
UIColor.redColor(),
UIColor.orangeColor(),
UIColor.yellowColor(),
UIColor.greenColor(),
UIColor.blueColor()
]
Run Code Online (Sandbox Code Playgroud)
目标是转移阵列:
如果我们想要以橙色(原始数组中索引1处的颜色)开始,则数组将如下所示:
let colorArray = [
UIColor.orangeColor(),
UIColor.yellowColor(),
UIColor.greenColor(),
UIColor.blueColor(),
UIColor.redColor(),
]
Run Code Online (Sandbox Code Playgroud)
如果我们想要以绿色(原始数组中索引3处的颜色)开始,则数组将如下所示:
let colorArray = [
UIColor.greenColor(),
UIColor.blueColor(),
UIColor.redColor(),
UIColor.orangeColor(),
UIColor.yellowColor()
]
Run Code Online (Sandbox Code Playgroud) struct PlaygroundView: View {
func attributedString(string: String) -> AttributedString {
var text = AttributedString(string)
text.font = .largeTitle.bold()
text.foregroundColor = .blue
return text
}
var body: some View {
Text(attributedString(string: "Hello"))
}
}
Run Code Online (Sandbox Code Playgroud)
文档提到属性范围
AttributedString API 定义了常见用途的键,例如文本样式、语义标记可格式化类型(例如日期和数字)以及超链接。您可以在 AttributeScopes 枚举中找到这些属性,其中包含 Foundation、SwiftUI、UIKit 和 AppKit 的属性。
这是描边颜色属性的描边颜色,但它似乎什么也没做。
struct PlaygroundView: View {
func attributedString(string: String) -> AttributedString {
var text = AttributedString(string)
text.font = .largeTitle.bold()
text.foregroundColor = .blue
text.strokeWidth = 5
text.strokeColor = .red
return text
} …
Run Code Online (Sandbox Code Playgroud) 手头的问题是响应者链.根据Apple的说法:
此外,在macOS 10.10及更高版本中,视图控制器参与响应者链.NSViewController
如果我在macOS故事板中使用标准segue,则目标视图控制器的行为与预期一致 - 焦点,键等效,响应者链等.
但是,如果我使用自定义segue,目标视图控制器不会按预期运行:(具体而言,密钥等效项神秘地无法工作 - 但是,在测试中,来自源视图控制器的按钮上的等效键继续工作(这不是' t help/desired)
在macOS 10.12上,我使用以下自定义segue ...我做错了什么?
class PushSegue: NSStoryboardSegue {
override func perform() {
(sourceController as AnyObject).presentViewController(destinationController as! NSViewController, animator: PushAnimator())
}
}
class PushAnimator: NSObject, NSViewControllerPresentationAnimator {
func animatePresentation(of viewController: NSViewController, from fromViewController: NSViewController) {
viewController.view.wantsLayer = true
viewController.view.frame = CGRect(x: fromViewController.view.frame.size.width, y: 0,
width: fromViewController.view.frame.size.width, height: fromViewController.view.frame.size.height)
fromViewController.addChildViewController(viewController)
fromViewController.view.addSubview(viewController.view)
let futureFrame = CGRect(x: 0, y: 0, width: viewController.view.frame.size.width,
height: …
Run Code Online (Sandbox Code Playgroud) 我的时钟时间是2012-04-12 09:37:01 +0000但是我的代码输出显示2h延迟.有人为什么呢?
NSDate *today;
today = [[NSDate alloc] init];
Run Code Online (Sandbox Code Playgroud)
---在输出字段/调试器中==>
(lldb) po today
(NSDate *) $3 = 0x06a3a8c0 2012-04-12 07:37:01 +0000
Run Code Online (Sandbox Code Playgroud) 给定一个简短的URL https://itun.es/us/JB7h_,如何将其扩展为完整的URL?
ios ×9
swift ×5
macos ×3
ios7 ×2
objective-c ×2
osx-yosemite ×2
uikit ×2
appkit ×1
arrays ×1
cocoa ×1
core-data ×1
dictation ×1
ios5 ×1
ios6 ×1
ios7.1 ×1
macos-sierra ×1
movie ×1
nsresponder ×1
nstableview ×1
nsurlsession ×1
swiftui ×1
twitter ×1
uiappearance ×1
uikeyboard ×1
uitextinput ×1
video ×1
watchkit ×1
watchos ×1
xcode ×1
xcode4.2 ×1