小编dan*_*hed的帖子

SwiftUI Segmented Picker 点击时不会切换

我正在尝试使用 SwiftUI 实现分段控制。由于某种原因,分段选取器在单击时不会在值之间切换。我浏览了很多教程,但找不到与我的代码有任何区别:

struct MeetingLogin: View {
    @State private var selectorIndex: Int = 0

    init() {
        UISegmentedControl.appearance().backgroundColor = UIColor(named: "JobsLightGreen")
        UISegmentedControl.appearance().selectedSegmentTintColor = UIColor(named: "AlmostBlack")
        UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.white,
                                                                .font: UIFont(name: "OpenSans-Bold", size: 13)!],
                                                               for: .selected)
        UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.white,
                                                                .font: UIFont(name: "OpenSans-Regular", size: 13)!],
                                                               for: .normal)
    }

    var body: some View {
        VStack {

            ...

            Group {
                Spacer().frame(minHeight: 8, maxHeight: 30)
                Picker("video", selection: $selectorIndex) {
                    Text("Video On").tag(0)
                    Text("Video Off").tag(1)
                }
                .pickerStyle(SegmentedPickerStyle())
                .padding([.leading, .trailing], 16)

                Spacer().frame(minHeight: 8, maxHeight: 50)
                Button(action: { self.sendPressed() }) {
                    ZStack …
Run Code Online (Sandbox Code Playgroud)

picker uisegmentedcontrol uipickerview swift swiftui

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

如何在iOS10(Swift 3)中获取现在播放歌曲的歌词

我想显示当前由iOS系统播放器播放的歌曲中的歌词.

这是我的自定义播放器:

import UIKit
import MediaPlayer
import AVFoundation

class NowPlayingController: NSObject {
    var musicPlayer: MPMusicPlayerController {
        if musicPlayer_Lazy == nil {
            musicPlayer_Lazy = MPMusicPlayerController.systemMusicPlayer()

            let center = NotificationCenter.default
            center.addObserver(self,
                selector: #selector(self.playingItemDidChange),
                name: NSNotification.Name.MPMusicPlayerControllerNowPlayingItemDidChange,
                object: musicPlayer_Lazy)
            musicPlayer_Lazy!.beginGeneratingPlaybackNotifications()
        }

        return musicPlayer_Lazy!
    }
    private var musicPlayer_Lazy: MPMusicPlayerController?

    var nowPlaying: MPMediaItem?

    //If song changes
    func playingItemDidChange(notification: NSNotification) {
        nowPlaying = musicPlayer.nowPlayingItem
    }
}
Run Code Online (Sandbox Code Playgroud)

为了获得nowPlaying项目的歌词,我尝试了两种方法,并且它们都会返回nil.

此代码始终返回nil:

let lyricsText = nowPlaying?.value(forProperty: MPMediaItemPropertyLyrics) as? NSString as String?
Run Code Online (Sandbox Code Playgroud)

在以下代码中MPMediaItemPropertyAssetURL始终返回nil …

avfoundation mpmediaitem ios swift swift3

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