如果UIViewController没有访问权限,我似乎无法获得最高分UINavigationController.这是我到目前为止:
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
但是,它似乎没有做任何事情.在keyWindow和rootViewController似乎是非零值太多,所以可选的链接不应该是一个问题.
注意: 做这样的事情是个坏主意.它打破了MVC模式.
我试图用Swift获取UIImage中像素的颜色,但它似乎总是返回0.这是代码,从@Minas的答案转换到这个线程:
func getPixelColor(pos: CGPoint) -> UIColor {
var pixelData = CGDataProviderCopyData(CGImageGetDataProvider(self.CGImage))
var data: UnsafePointer<UInt8> = CFDataGetBytePtr(pixelData)
var pixelInfo: Int = ((Int(self.size.width) * Int(pos.y)) + Int(pos.x)) * 4
var r = CGFloat(data[pixelInfo])
var g = CGFloat(data[pixelInfo+1])
var b = CGFloat(data[pixelInfo+2])
var a = CGFloat(data[pixelInfo+3])
return UIColor(red: r, green: g, blue: b, alpha: a)
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我一直在编写应用程序,使用CloudKit会让我的生活变得更轻松.但是,此应用程序需要iOS应用程序旁边的基于Web的应用程序.我想知道是否有任何方法可以将CloudKit与Android或基于Web的应用程序结合使用.
虽然使用Apple提供的API可能无法直接实现这一点,但另一种可能性是将OS X Server用于CloudKit.是否可以/遵守Apple的CloudKit服务条款?
谢谢!
当我开始想知道UITableView中的"beginUpdates"和UICollectionView中的"performBatchUpdates"是否具有相同的行为时,我正在浏览文档.如果是这样,有没有理由,他们被称为不同,即使他们几乎是一样的东西?
谢谢!
我正在尝试在macOS Sierra上的Xcode 8(稳定版)中创建一个没有故事板的macOS应用程序.但是,我AppDelegate甚至没有被发起.这是我的代码:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
override init() {
super.init()
print("Init")
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
print("Finished launching")
// Create a window
window = NSWindow()
// Add the view controller
let viewController = ViewController()
window.contentView?.addSubview(viewController.view)
// Show the window
window.makeKeyAndOrderFront(nil)
}
}
Run Code Online (Sandbox Code Playgroud)
无论是init或applicationDidFinishLaunching(_ aNotification: Notification)将被调用.任何帮助将非常感激.
我最近试图将代码从这里转换为Swift.但是,无论图像如何,我都会保持白色.这是我的代码:
// Playground - noun: a place where people can play
import UIKit
extension UIImage {
func averageColor() -> UIColor {
var colorSpace = CGColorSpaceCreateDeviceRGB()
var rgba: [CGFloat] = [0,0,0,0]
var context = CGBitmapContextCreate(&rgba, 1, 1, 8, 4, colorSpace, CGBitmapInfo.fromRaw(CGImageAlphaInfo.PremultipliedLast.toRaw())!)
rgba
CGContextDrawImage(context, CGRectMake(0, 0, 1, 1), self.CGImage)
if rgba[3] > 0 {
var alpha = rgba[3] / 255
var multiplier = alpha / 255
return UIColor(red: rgba[0] * multiplier, green: rgba[1] * multiplier, blue: rgba[2] * multiplier, alpha: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用一个在SpriteKit中创建一个叠加层SKSpriteNode.但是,我希望触摸通过叠加层,所以我设置isUserInteractionEnabled为false.但是,当我这样做时,SKSpriteNode仍然似乎吸收了所有的触摸,并且不允许底层节点做任何事情.
这是我正在谈论的一个例子:
class
TouchableSprite: SKShapeNode {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("Touch began")
}
}
class GameScene: SKScene {
override func sceneDidLoad() {
// Creat touchable
let touchable = TouchableSprite(circleOfRadius: 100)
touchable.zPosition = -1
touchable.fillColor = SKColor.red
touchable.isUserInteractionEnabled = true
addChild(touchable)
// Create overlay
let overlayNode = SKSpriteNode(imageNamed: "Fade")
overlayNode.zPosition = 1
overlayNode.isUserInteractionEnabled = false
addChild(overlayNode)
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了子类化SKSpriteNode并手动将触摸事件委托给适当的节点,但这会导致很多奇怪的行为.
任何帮助将非常感激.谢谢!
ios ×5
swift ×5
uiimage ×2
android ×1
cloudkit ×1
macos ×1
sprite-kit ×1
touch ×1
uitableview ×1
xcode ×1