我最近升级到了Xcode 9-beta和iOS 11.当我做了并推动我的项目播放时,我的所有视图都被状态栏向下推了大约20px,而不是状态栏直接在我的视图之上.我的合作伙伴,拥有iOS 10,没有这个问题.我附上了截图供您参考.
有人可以提供一些建议吗?任何帮助将非常感激.非常感谢提前.
我想访问用户的联系人,并计划使用Apple提供的Contacts和ContactsUI框架.
首先,我需要获得访问用户联系人的权限,并且无法这样做.在Swift 2中,可以像这样请求许可:
func requestForAccess(completionHandler: (accessGranted: Bool) -> Void) {
let authorizationStatus = CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts)
switch authorizationStatus {
case .Authorized:
completionHandler(accessGranted: true)
case .Denied, .NotDetermined:
self.contactStore.requestAccessForEntityType(CNEntityType.Contacts, completionHandler: { (access, accessError) -> Void in
if access {
completionHandler(accessGranted: access)
}
else {
if authorizationStatus == CNAuthorizationStatus.Denied {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let message = "\(accessError!.localizedDescription)\n\nPlease allow the app to access your contacts through the Settings."
self.showMessage(message)
})
}
}
})
default:
completionHandler(accessGranted: false)
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试将它转换为Swift 3,但仍然会出现错误.错误是"实例成员'异步'不能在类型'DispatchQueue'上使用;你的意思是使用这种类型的值吗?":
func requestForAccess(completionHandler: @escaping …Run Code Online (Sandbox Code Playgroud) 我是JS的新手,我有一个JSON文件,我需要发送到我的服务器(Express),然后我可以解析并在我正在构建的Web应用程序中使用它的内容.
这就是我现在拥有的:
一些糟糕的代码:
app.get('/ search',function(req,res){res.header("Content-Type",'application/json'); res.send(JSON.stringify({/ data.json /})) ;});
在上面的代码中,我只是尝试将文件发送到localhost:3000/search并查看我的JSON文件,但是当我走到那条路径时我收到的是{}.谁能解释一下?
任何帮助都会非常感激.非常感谢提前.
干杯,西奥
data.json中的示例代码段:
[{
"name": "Il Brigante",
"rating": "5.0",
"match": "87",
"cuisine": "Italian",
"imageUrl": "/image-0.png"
}, {
"name": "Giardino Doro Ristorante",
"rating": "5.0",
"match": "87",
"cuisine": "Italian",
"imageUrl": "/image-1.png"
}]
Run Code Online (Sandbox Code Playgroud) 我已经被一个错误困扰了几个小时。我正在使用 Alamofire 构建一个框架,并在 iOS 项目中测试它。每当我运行该项目时,我都会收到此错误:
dyld:未加载库:@rpath/Alamofire.framework/Alamofire 引用自:/Users/theodorestrauss/Library/Developer/Xcode/DerivedData/TGClient-ecnnvvvxipoufihfghkpxlfccyoc/Build/Products/Debug-iphonesimulator/TGClient.framework/TGClient 原因:图像未找到
我在网上搜索了 GitHub 问题、Stack 文章等。我清理、删除了派生数据,从嵌入式二进制文件中添加和删除了框架等。
对于任何人来说,这都不是重复的。所有其他问题和答案都已过时。
如果有人可以提供帮助,我将非常感激。预先非常感谢。干杯,
西奥
我通过向上和向下滑动来在屏幕上和屏幕外设置一个 UIView 动画。我使用此代码来做到这一点:
private var _animator: AnyObject?
@available(iOS 10.0, *)
var animator: UIViewPropertyAnimator? {
get {
return _animator as? UIViewPropertyAnimator
}
set {
_animator = newValue
}
}
var haveTheySwiped = false
var haveTheyNotSwiped = true
@available(iOS 10.0, *)
func handlePan(recognizer: UIPanGestureRecognizer) {
let vel = recognizer.velocity(in: self)
switch recognizer.state {
case .began:
if vel.y < 0 && !haveTheySwiped {
animator = UIViewPropertyAnimator(duration: 1, curve: .easeOut, animations: {
self.backgroundImage.frame = self.backgroundImage.frame.offsetBy(dx: 0, dy: -603)
})
haveTheySwiped = true
isScanVisible = …Run Code Online (Sandbox Code Playgroud) 我正在尝试与Playground中的手势识别器一起工作,但遇到了一些麻烦。
这是我的课:
class foo {
var fooVarSwipe: Any
var fooVarTap: Any
init() {
let gr = UISwipeGestureRecognizer(target: self, action: #selector(foo.bar))
let tr = UITapGestureRecognizer(target: self, action: #selector(foo.tar))
helloApple.addGestureRecognizer(gr)
helloApple.addGestureRecognizer(tr)
helloApple.isUserInteractionEnabled = true
self.fooVarSwipe = gr
self.fooVarTap = tr
}
@objc func tar() {
print("tapped")
}
@objc func bar() {
print("swiped")
currentViewNum = 1
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是在以“ let gr”开头的行上说“初始化前使用了变量'self.fooVarSwipe'”。为什么是这样?我在外面初始化该类,但仍向我显示错误。
任何帮助将非常感激!!衷心感谢您,Theo
我想创建一个IBAction来在我的应用程序中打开iOS本机相机应用程序,但我似乎无法在线找到相机应用程序的地址。
我知道消息是:UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
有谁知道哪个是正确的方案?
我正在尝试创建一个一起动画的箭头。但是,有两个问题:
1.线条没有动画,整个箭头只是出现在屏幕上
2.箭头填充为黑色,而不仅仅是轮廓(我的目标是)
let shapeLayer = CAShapeLayer()
let bezierPath = UIBezierPath()
//set up lines
bezierPath.move(to: CGPoint(x: 50.5, y: 158.5))
bezierPath.addLine(to: CGPoint(x: 221.5, y: 158.5))
bezierPath.addLine(to: CGPoint(x: 171.5, y: 108.5))
bezierPath.addLine(to: CGPoint(x: 197.5, y: 82.5))
bezierPath.addLine(to: CGPoint(x: 292.5, y: 177.5))
bezierPath.addLine(to: CGPoint(x: 197.5, y: 272.5))
bezierPath.addLine(to: CGPoint(x: 171.5, y: 246.5))
bezierPath.addLine(to: CGPoint(x: 221.5, y: 196.5))
bezierPath.addLine(to: CGPoint(x: 50.5, y: 196.5))
bezierPath.addLine(to: CGPoint(x: 50.5, y: 158.5))
UIColor.black.setStroke()
bezierPath.lineWidth = 1
bezierPath.stroke()
shapeLayer.path = bezierPath.cgPath
// set up animation
let animation2 = CABasicAnimation(keyPath: …Run Code Online (Sandbox Code Playgroud)