小编use*_*523的帖子

用AVAudioPlayer播放声音

我正试图播放声音,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)

audio avaudioplayer ios swift

72
推荐指数
5
解决办法
9万
查看次数

iOS在2个导航控制器之间切换

在我的应用程序中,如果用户未登录,则会显示嵌入在导航控制器中的登录控制器.用户登录后,应用程序应切换到其他导航控制器以显示应用程序.

当用户登录时,如何从一个导航控制器切换到另一个导航控制器.?

谢谢

在此输入图像描述

我正在检查用户是否登录了应用程序代理:

 // 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)

uinavigationcontroller ios swift

17
推荐指数
1
解决办法
7626
查看次数

UITableView - 多选和单选

我的UITableView中有2个部分.
我希望第一部分允许多个单元格选择,第二部分只允许单个选择.
我尝试了一些代码,但效果不佳.
尽可能快速编码.谢谢.

在此输入图像描述

uitableview swift xcode7

9
推荐指数
2
解决办法
6838
查看次数

在图像右上角绘制文本

我想在 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)

uiimage ios swift

5
推荐指数
1
解决办法
1260
查看次数

我的 MacOS 应用程序的数据库位于哪里?

使用 Core Data 时,MacOS 应用程序的数据库位置是什么?

我在 Mac 上到处搜索,但没有找到。
我关闭了隐藏文件,并且确信我的数据库中有数据。另外我不使用应用程序沙箱。

macos cocoa core-data macos-sierra

1
推荐指数
1
解决办法
2059
查看次数

在不使用UIImagePickerController的情况下获取UIImage元数据

如何在不使用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)

uiimage ios swift

1
推荐指数
1
解决办法
1659
查看次数