我正试图播放声音,AVAudioPlayer但它无法正常工作.
编辑1:仍然无法正常工作.
编辑2:此代码有效.我的设备处于静音模式.
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("button-09", ofType: "wav"))
println(alertSound)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,如果用户未登录,则会显示嵌入在导航控制器中的登录控制器.用户登录后,应用程序应切换到其他导航控制器以显示应用程序.
当用户登录时,如何从一个导航控制器切换到另一个导航控制器.?
谢谢
我正在检查用户是否登录了应用程序代理:
// Check if user is log
let currentUser = PFUser.currentUser()
if currentUser != nil {
// Do stuff with the user
} else {
// Show the signup or login screen
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let nav = mainStoryboardIpad.instantiateViewControllerWithIdentifier("LogInController") as! UINavigationController
self.window?.rootViewController = nav
}
Run Code Online (Sandbox Code Playgroud)
解决方案:看起来很有效
当用户按下logIn按钮时:
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let nav = mainStoryboardIpad.instantiateViewControllerWithIdentifier("MainNavController") as! UINavigationController
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = nav
Run Code Online (Sandbox Code Playgroud) 我想在 UIImage 的右上角或右下角绘制一个文本。我有一个扩展程序可以很好地绘制文本,但问题是将文本定位在屏幕右侧(因为文本被剪切)。
这是扩展名:
extension UIImage {
func addText(drawText: NSString, atPoint: CGPoint, textColor: UIColor?, textFont: UIFont?) -> UIImage{
// Setup the font specific variables
var _textColor: UIColor
if textColor == nil {
_textColor = UIColor.white
} else {
_textColor = textColor!
}
var _textFont: UIFont
if textFont == nil {
_textFont = UIFont.systemFont(ofSize: 50)
} else {
_textFont = textFont!
}
// Setup the image context using the passed image
UIGraphicsBeginImageContext(size)
// Setup the font attributes that will be later …Run Code Online (Sandbox Code Playgroud) 使用 Core Data 时,MacOS 应用程序的数据库位置是什么?
我在 Mac 上到处搜索,但没有找到。
我关闭了隐藏文件,并且确信我的数据库中有数据。另外我不使用应用程序沙箱。
如何在不使用UIImagePickerController的情况下获取UIImage元数据。
我基本上有一个变量UIImage,我想获取元数据。
例如,我将需要类似“ myImage.date”的内容来访问日期。
编辑1:我尝试这样做,但是崩溃(在exif var上找到nil)
func getData(image: UIImage) {
guard let data = UIImageJPEGRepresentation(image, 1),
let source = CGImageSourceCreateWithData(data as CFData, nil) else { return}
let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil)
let a = Unmanaged.passUnretained(kCGImagePropertyExifDateTimeOriginal).toOpaque()
let exif = CFDictionaryGetValue(imageProperties, a)
print(exif)
}
Run Code Online (Sandbox Code Playgroud) swift ×5
ios ×4
uiimage ×2
audio ×1
cocoa ×1
core-data ×1
macos ×1
macos-sierra ×1
uitableview ×1
xcode7 ×1