CardPlayer卡未加载

时间:2019-02-28 07:21:58

标签: ios objective-c swift iphone cocoapods

在Cards项目中,https://github.com/PaoloCuscela/Cards我下载了该应用程序并运行它,但CardPlayer Card遇到一个问题。加载视图时未加载。 如果在应有卡片的白色区域中单击,它将弹出并显示。似乎未加载卡信息。

视图加载时

enter image description here

点击应插入卡的区域

enter image description here

这是调试器控制台所说的

Loaded!
CARDS: Something wrong with the video source URL
CARDS: Something wrong with the video source URL
2019-02-27 23:08:50.208 Demo[1841:237619] Failed to set (icon) user 
defined inspected property on (Cards.CardPlayer): [<Cards.CardPlayer 
0x15d7c6a0> setValue:forUndefinedKey:]: this class is not key value 
coding-compliant for the key icon.
Loaded!
2019-02-27 23:08:55.120 Demo[1841:237619] <UIVisualEffectView 
0x15e7da20> is being asked to animate its opacity. This will cause the 
effect to appear broken until opacity returns to 1.

有人知道怎么回事吗?

更新:卡布局功能

 override open func layout(animating: Bool = true) {
    super.layout(animating: animating)

    let gimme = LayoutHelper(rect: backgroundIV.bounds)

    let aspect1016 = backgroundIV.bounds.width *  (10/16)
    let aspect921 = backgroundIV.bounds.width *  (9/21)
    let move = ( aspect1016 - aspect921 ) * 2

    subtitleLbl.transform = isPresenting ? 
CGAffineTransform(translationX: 0, y: move) : CGAffineTransform.identity
    backgroundIV.frame.size.height = originalFrame.height + ( 
isPresenting ? move/2 : 0 )
    // Issue is here: Line 208
    let currentHeigh = backgroundIV.frame.size.height
    backgroundIV.frame.size.height = originalFrame.height + ( 
isPresenting ? move/2 : 0 )

    if backgroundIV.frame.size.height <= 0 {
        print ("heigh is 0")
        backgroundIV.frame.size.height = currentHeigh
    }
    player.view.frame.origin = CGPoint.zero
    player.view.frame.size = CGSize(width: backgroundIV.bounds.width, 
height: isPresenting ? aspect1016 : aspect921 )
    playerCoverIV.frame = player.view.bounds


    playPauseV.center = player.view.center
    playIV.center = 
playPauseV.contentView.center.applying(CGAffineTransform(translationX: 
LayoutHelper.Width(5, of: playPauseV), y: 0))

    categoryLbl.frame.origin.y = gimme.Y(3, from: player.view)
    titleLbl.frame.origin.y = gimme.Y(0, from: categoryLbl)
    titleLbl.sizeToFit()

    categoryLbl.frame = CGRect(x: insets,
                               y: gimme.Y(3, from: player.view),
                               width: gimme.X(80),
                               height: gimme.Y(5))

    titleLbl.frame = CGRect(x: insets,
                            y: gimme.Y(0, from: categoryLbl),
                            width: gimme.X(70),
                            height: gimme.Y(12))
    titleLbl.sizeToFit()

    subtitleLbl.frame = CGRect(x: insets,
                               y: gimme.RevY(0, height: gimme.Y(14)) - 
insets,
                               width: gimme.X(80),
                               height: gimme.Y(12))
}


//MARK: - Actions

public func play() {

    player.playFromCurrentTime()
    UIView.animate(withDuration: 0.2) {
        self.playPauseV.transform = CGAffineTransform(scaleX: 0.1, y: 
0.1)
        self.playPauseV.alpha = 0
    }
}

public func pause() {

    player.pause()
    UIView.animate(withDuration: 0.1) {
        self.playPauseV.transform = CGAffineTransform.identity
        self.playPauseV.alpha = 1
    }
}

public func stop() {

    pause()
    player.stop()
}

@objc  func playTapped() {

    play()
    delegate?.cardPlayerDidPlay?(card: self)
}

@objc  func playerTapped() {

    pause()
    delegate?.cardPlayerDidPause?(card: self)
}

open override func touchesBegan(_ touches: Set<UITouch>, with event: 
UIEvent?) {
    if touches.first?.view == player.view || touches.first?.view == 
playPauseV.contentView { playerTapped() }
    else { super.touchesBegan(touches, with: event) }
}

}


// Player Delegates
extension CardPlayer: PlayerDelegate {
public func playerReady(_ player: Player) {

    player.view.addSubview(playPauseV)
    playPauseV.frame.size = CGSize(width: playBtnSize, height: 
playBtnSize)
    playPauseV.layer.cornerRadius = playPauseV.frame.height/2
    playIV.frame.size = CGSize(width: LayoutHelper.Width(50, of: 
playPauseV),
                               height: LayoutHelper.Width(50, of: 
playPauseV))
    playPauseV.center = player.view.center
    playIV.center = 
playPauseV.contentView.center.applying(CGAffineTransform(translationX: 
LayoutHelper.Width(5, of: playPauseV), y: 0))

    if isAutoplayEnabled {

        play()
    } else {
        pause()
    }
}

public func playerPlaybackStateDidChange(_ player: Player) { }
public func playerBufferingStateDidChange(_ player: Player) { }
public func playerBufferTimeDidChange(_ bufferTime: Double) { }
}

extension CardPlayer: PlayerPlaybackDelegate {

public func playerPlaybackDidEnd(_ player: Player) {

    if shouldRestartVideoWhenPlaybackEnds { player.playFromBeginning() 
}
    else { playerTapped()  }

}

public func playerPlaybackWillLoop(_ player: Player) { }
public func playerCurrentTimeDidChange(_ player: Player) { }
public func playerPlaybackWillStartFromBeginning(_ player: Player) { }
}

已解决backgroundIV.frame.size.height = 300添加到了CardPlayer.swift的208个

由@Shadowsheep聊天提供

1 个答案:

答案 0 :(得分:1)

问题在CardPlayer.swift类上,特别是在207backgroundIV.frame.size.height = originalFrame.height + ( isPresenting ? move/2 : 0 ))行下

controller加载时,height的{​​{1}}被设置为backgroundIV

添加此检查(在0行下)应该可以解决您的问题。

207

此错误

// Issue is here
let currentHeight = backgroundIV.frame.size.height // <-- new line to store current value
/* this is line #207 */ backgroundIV.frame.size.height = originalFrame.height + ( isPresenting ? move/2 : 0 ) // This is line 207

// This is the check
if backgroundIV.frame.size.height <= 0 {
    print ("heigh is 0")
    backgroundIV.frame.size.height = currentHeight
}

与用户定义的运行时属性相关,该属性设置为Failed to set (icon) user defined inspected property on (Cards.CardPlayer): [<Cards.CardPlayer 0x15d7c6a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key icon. 中不属于CardPlayer的视图(如果需要,可以将其删除)

enter image description here