我正在快速制作音乐应用。该应用程序允许用户通过其Apple Music应用程序通过其Apple Music订阅播放音乐。我可以通过以下方式检查用户是否有Apple Music订阅:
SKCloudServiceController().requestCapabilities { (capability:SKCloudServiceCapability, err:Error?) in
guard err == nil else {
print("error in capability check is \(err!)")
return
}
if capability.contains(SKCloudServiceCapability.musicCatalogPlayback) {
print("user has Apple Music subscription")
}
if capability.contains(SKCloudServiceCapability.musicCatalogSubscriptionEligible) {
print("user does not have subscription")
}
}
Run Code Online (Sandbox Code Playgroud)
但是:在某些情况下,某些人会由于某种原因而订阅了Apple Music,但没有在设备上下载Apple Music应用。如果用户有订阅但没有设备,那么我想实质上将这种情况视为他们根本没有订阅,即我们无法通过Apple Music播放音乐。
因此,我一直在寻找添加检查Apple Music是否在用户设备上的方法。我找到了这个答案:检查是否使用Swift结合此资源安装了应用程序,以查找Apple Music的url方案,并得出结论,我可以通过以下方式检查用户是否同时在其设备上安装了Apple Music订阅和 Apple Music应用程序:
SKCloudServiceController()requestCapabilities { (capability:SKCloudServiceCapability, err:Error?) in
guard err == nil else {
print("error in capability check is \(err!)") …Run Code Online (Sandbox Code Playgroud) 我正在制作一个应用程序,它以类似于苹果地图的方式返回场地(如餐馆),即最初隐藏在屏幕外的表格视图,然后在要显示表格视图的内容时向上移动到其他内容上方。
这是我到目前为止得到的:
您会注意到,当将 table view 拉回以显示其后面的地图时,table view 不会以一种流畅的运动向下移动。事实上,当表格视图到达它的“顶部”时,您会注意到右侧的滚动条是可见的,但视图并没有移动。这是因为,在录制时,我正在向下拖动,但视图需要一些时间才能真正开始向下平移。我将解释为什么它有这种延迟,但首先将此行为与 Apple 地图表视图的行为进行比较:

请注意 Apple 地图表视图从转换视图本身到滚动滚动视图的过渡中的流动性。当视图的 minY 到达某个点时,视图的向上平移转换为滚动视图的向下滚动(反之亦然)。这一切都在用户向上滑动的整个过程中完成。
现在我将解释我为创建翻译滚动视图所做的工作。滚动视图本身是一个嵌入在地图视图控制器上的容器视图中的 UITableViewController。

包含容器视图的视图具有平移手势识别器。当平移手势识别器的状态为 UIGestureRecognizerState.ended 时,即拖动已结束,它会检查容器视图的 minY 与预定 Y 坐标的关系。如果 minY 小于预定的 Y 坐标,它将动画容器视图以将其 minY 对齐到该 Y 坐标。如果 minY 略大于预定的 Y 坐标,则情况相同,在这种情况下,容器视图将向上动画,因此它的 minY 捕捉到这个预定的 Y 坐标。

一旦视图捕捉到这个位置,嵌入的 UITableViewController 的“.isScrollEnabled”属性,它最初设置为 false,现在设置为 true。当嵌入的表格视图现在启用滚动时,用户执行的拖动将滚动表格视图而不是平移容器视图。为了撤消此操作,我已将其设置为当表视图到达其滚动的顶部时,其“.isScrollEnabled”属性将设置回 false。这意味着用户的任何拖动动作都将平移视图而不是滚动表格视图。这不会像 Apple 地图那样在滚动和翻译之间创建流畅的过渡。用户实际上必须在该区域上执行多次拖动才能从滚动过渡到平移;
这是我在容器视图的父视图控制器中使用的代码:
将嵌入式表视图控制器的 .isScrollEnabled 属性更改为 true
@objc func handlePan(sender: UIPanGestureRecognizer) {
let resultView = self.resultView
let translation = sender.translation(in: view)
switch sender.state {
case .began, .changed:
resultView?.center = CGPoint(x: (resultView?.center.x)!, y: (resultView?.center.y)! …Run Code Online (Sandbox Code Playgroud)Im trying to adjust the mouse position to the center of a target window position. To do so, I precalculate the X and Y coordinates that leads to the center position. To perform the mouse move, I am using "SetCursorPos" method from the winapi. My issue is now that the function does not align the x value properly if the cursor is at a lower resolution display (Full HD) and the move has to be performed to a higher resolution …
我正在使用Mapbox创建iOS应用程序。应用程序获取对我的API的请求,该请求以JSON格式返回地图边界框内发生的许多事件。
我以前没有使用聚类,因此某些地图注释只是覆盖了其他注释。我正在使用此Mapbox教程,该教程MGLShapeCollectionFeature从GeoJSON文件创建,MGLShapeSource从形状收集功能创建,然后将标记层创建为MGLSymbolStyleLayer,将圆圈层创建为MGLCircleStyleLayer,将数字层创建为MGLSymbolStyleLayer。标记层在地理上显示每个事件,圆圈层和数字层合在一起表示每个聚类的标记数。
最终产品应类似于Mapbox示例:
此示例使用GeoJSON文件在世界地图上显示群集海港。
以下是该示例用于将上述GeoJSON转换为相关源和图层以填充地图的相关代码:
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "ports", ofType: "geojson")!)
let source = MGLShapeSource(identifier: "clusteredPorts",
url: url,
options: [.clustered: true, .clusterRadius: icon.size.width])
style.addSource(source)
// Use a template image so that we can tint it with the `iconColor` runtime styling property.
style.setImage(icon.withRenderingMode(.alwaysTemplate), forName: "icon")
// Show unclustered features as icons. The `cluster` attribute is built into clustering-enabled
// source features.
let ports = MGLSymbolStyleLayer(identifier: …Run Code Online (Sandbox Code Playgroud) 我的问题: 我正在用 C++ 编写一个国际象棋引擎。编写国际象棋引擎的一部分是处理非常大的数字(可以想象高达 2^63)。我有一个正在为我的项目运行单元测试的文件,当我尝试运行构建任务以将其编译为可执行文件时,出现以下错误:
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: too many sections (32782)
C:\Users\chopi\AppData\Local\Temp\ccCF1XuS.s: Assembler messages:
C:\Users\chopi\AppData\Local\Temp\ccCF1XuS.s: Fatal error: can't write 293 bytes to section .text of C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: 'File too big'
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: too many sections (32782)
C:\Users\chopi\AppData\Local\Temp\ccCF1XuS.s: Fatal error: can't close C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: File too big
The terminal process "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe' -g c:\Users\chopi\Desktop\chess-engine\maestro-tests\main.cpp -o c:\Users\chopi\Desktop\chess-engine\maestro-tests\main.exe" terminated with exit code: 1.
Run Code Online (Sandbox Code Playgroud)
基本上,章节太多了。因此,我去寻找答案,发现很多地方解释了如何配置bigobjVisual Studio,但没有解释如何配置Visual Studio Code。
我尝试过的:
它应该像编译时传递/bigobj、-bigobj或两者 …
所以我目前正在 Xcode 中使用 SpriteKit 制作游戏并使用 Swift 进行编码。我想知道是否有一种方法可以在满足特定条件时将单个孩子从父母中删除。我看到了removeAllChildren()方法和removeChildren(in:[SKNode])。我不想删除所有子项,而且我还没有找到一种方法使removeChildren(in:[SKNode])方法为我工作。任何帮助将不胜感激(也许解释如何使用上述内容来删除特定的孩子?)。谢谢。
大卫
我正在使用 swift 制作一个应用程序,该应用程序调用 Google Places api 以生成位置的 JSON 文件,包括生成的位置图像。这些图像作为 URL 给出,我需要将它们转换为 UIImage,然后将这些图像附加到数组中。打开 URL 的内容时,我可以看到图像,但这些图像没有附加到数组中。这是我的视图控制器的类,它试图生成所述图像:
import Foundation
import UIKit
import WebKit
class ImageViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var photos: [Photo]?
var uiImages: [UIImage]?
override func viewDidLoad() {
for photo in photos! {
let url = URL(string:"https://maps.googleapis.com/maps/api/place/photo?photoreference=\(photo.reference)&sensor=false&maxheight=\(photo.height)&maxwidth=\(photo.width)&key=AIzaSyC_SoYT7VnYnyz3GAb7qqbXjZeLFG5GE70")
let data = try? Data(contentsOf: url!)
let image: UIImage = UIImage(data: data!)!
self.uiImages?.append(image)
print(image)
print(self.uiImages)
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这个循环中,我告诉代码在追加发生后打印“image”和数组“uiImages”。但是,我在打印图像数组时返回 nil,但对于图像本身不返回 nil。

我觉得这可能与方法的异步有关,但我也尝试在主线程上附加,但这并没有改变任何东西。此外,“photos”变量不是 nil,它是在视图控制器实例化时设置的。
这是 Photo 类的代码:
import Foundation
struct Photo {
var …Run Code Online (Sandbox Code Playgroud) swift ×5
ios ×4
apple-music ×1
asynchronous ×1
c# ×1
c++ ×1
g++ ×1
gcc ×1
mapbox ×1
mapbox-gl ×1
mapbox-ios ×1
mingw ×1
nsurl ×1
sprite-kit ×1
uiimage ×1
uiscrollview ×1
uitableview ×1
url ×1