Tag: swift2

斯威夫特:自定义相机保存与图像修改元数据

我正在尝试从图像样本缓冲区中保存一些元数据以及图像。 我需要: 将图像从元数据旋转到方向 从元数据中删除方向 保存到元数据的date 将该图像与元数据一起保存到文档目录中 我试图从数据创build一个UIImage,但是删除了元数据。 我已经尝试从数据中使用CIImage,它保留元数据,但我不能旋转它,然后将其保存到文件。 private func snapPhoto(success: (UIImage, CFMutableDictionary) -> Void, errorMessage: String -> Void) { guard !self.stillImageOutput.capturingStillImage, let videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo) else { return } videoConnection.fixVideoOrientation() stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) { (imageDataSampleBuffer, error) -> Void in guard imageDataSampleBuffer != nil && error == nil else { errorMessage("Couldn't snap photo") return } let data […]

“++”已被弃用:它将在Swift 3中被删除

在更新到Xcode 7.3 ,在我的项目中显示了一堆警告。 “++”已被弃用:它将在Swift 3中被删除 任何想法来解决这个警告? 为什么++和–将被弃用的任何原因?

在iOS上进行深度页面转换

我正在尝试创build一个animation,如Facebook菜单向下滑动POP框架的animation或完全像InShorts应用程序 。 Android文档涵盖了这个..但是在iOS中找不到任何提示。 我所尝试的是将细胞转化为 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { UIView.animateWithDuration(0.1, animations: { () -> Void in cell.transform = CGAffineTransformMakeScale(0.8, 0.8) }) } 但是,这并不像预期的那样工作。使用Google Googling,我发现这正是我想要实现的。 但是它在UIView 。 我认为这是最适合的,如果我们在UITableViewCellanimation? 我真的很感激有人愿意帮助这个问题。 这是我正在开发的启动项目

如何在同一个appdelegate.swift中同时使用google +和facebooklogin

我的应用程序使用谷歌+login和我的appdelegate.swift我有: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") GIDSignIn.sharedInstance().delegate = self return true } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: […]

在iOS中使用Swift捕获Javascript事件

我使用networking编程语言构build应用程序,并希望在用户单击HTMLbutton时启动相机。 由于我希望我的相机视图是一个自定义的,我需要用Swift来devise它。 所以当用户点击这个HTMLbutton时,我想在Swift中“捕捉”这个点击,这样我就可以开始我的本地相机视图。 我知道这可以用WKWebview来完成,但是我真的不知道该怎么做。 例如,我的Javascript(jQuery)代码可能看起来像这样: // User clicks to start the native camera with Swift $(".camera_button").click(function() { // Function to call the camera view from JS to Swift }); 你能帮我做这个吗? 谢谢。

Swift:使用协议扩展导致“无法识别的select器发送到实例”

我正在尝试在所有符合协议MyProtocol UIViewController上添加一个on-tapfunction。 下面是我如何做到这一点: import UIKit protocol MyProtocol: class{ var foo: String? {get set} func bar() } extension MyProtocol where Self: UIViewController { func bar() { print(foo) } } class TestViewController: UIViewController, MyProtocol{ var foo: String? override func viewDidLoad() { super.viewDidLoad() foo = "testing" let tapGesture = UITapGestureRecognizer(target: self, action: "bar") } 点击屏幕时会导致以下结果: Terminating app due […]

Swift 2 – 不能用CLLocationManager获取用户位置

这是我的VC代码: import UIKit import MapKit import CoreLocation class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { @IBOutlet weak var mapView: MKMapView! let locationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self locationManager.requestWhenInUseAuthorization() mapView.showsUserLocation = true } func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { mapView.showsUserLocation = (status == .AuthorizedAlways) } func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { […]

如何在纵向模式下lockingviewController

我很快就在iOS应用程序上开玩笑了。 我已经使用UITabBarController作为rootViewController。 我有一个viewControllervideo列表。 这个viewController只支持肖像模式和用户select一个video,然后使用showViewController方法进入playerController,它可以同时支持方向(纵向和横向模式)。 如果video播放完成,playerController会popupvideo列表控制器。每个事情都很好,但用户可以在video播放完成后旋转屏幕(如剩余时间1秒或0秒),然后video列表viewController进入横向模式。 我已经试过这个代码在纵向模式下设置玩家的方向。 let value = UIInterfaceOrientation.Portrait.rawValue UIDevice.currentDevice().setValue(value, forKey: "orientation") 但没有工作。 如何解决这个问题。

如何在Swift中增加UILabel中的行间距

我有一个有几行文本的标签,我想增加行间的间距。 其他人也有类似的问题,但解决scheme并没有解决我的问题。 此外,我的标签可能包含或不包含段落。 我是Swift新手。 有使用故事板的解决scheme吗? 还是只有通过NSAttributedstring它可能?

如何在Swift中列出符合协议的所有类?

如何列出在Swift中实现给定协议的所有类? 假设我们有一个例子: protocol Animal { func speak() } class Cat:Animal { func speak() { print("meow") } } class Dog: Animal { func speak() { print("Av Av!") } } class Horse: Animal { func speak() { print("Hurrrr") } } 这是我目前的(不可编译的)方法: func getClassesImplementingProtocol(p: Protocol) -> [AnyClass] { let classes = objc_getClassList() var ret = [AnyClass]() for cls […]