CardPlayer 卡未加载

Posted

技术标签:

【中文标题】CardPlayer 卡未加载【英文标题】:CardPlayer Card not loading 【发布时间】:2019-02-28 07:21:58 【问题描述】:

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

当视图加载时

当卡片应该加载的区域被点击时

这是调试器控制台所说的

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)  

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

感谢@Shadowsheep 聊天

【问题讨论】:

【参考方案1】:

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

controller 加载时,backgroundIVheight 设置为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.

与设置为Main.storyboard 中不属于 CardPlayer 的视图的用户定义运行时属性相关(如果需要,可以将其删除)

【讨论】:

感谢您的帮助。我将检查添加到第 207 行,问题似乎仍然存在。 @user3233623 它不应该。我已经尝试并测试过了。也许我们的文件不同,我今天从 GitHub 签出了 Card 演示。你能更新你的答案,显示你把支票放在哪里吗?您还可以发布整个 CardPlayer 布局功能。 @user3233623 是的,行是 207,你必须在第一个 frame.size.height 设置后测试 backgroundIV.frame.size.height = originalFrame.height + ( isPresenting ? move/2 : 0 ) ;-)。我已经更新了我的答案。把支票放在这行下面backgroundIV.frame.size.height = originalFrame.height + ( isPresenting ? move/2 : 0 ) @user3233623 看到我的其他 cmets,你必须检查之后,而不是在此行之前backgroundIV.frame.size.height = originalFrame.height + ( isPresenting ? move/2 : 0 ) 让我们continue this discussion in chat.

以上是关于CardPlayer 卡未加载的主要内容,如果未能解决你的问题,请参考以下文章

如果选项卡未处于活动状态,jqgrid 无法在 jquery-ui 选项卡下正确加载

网络选项卡未显示应用在选择器上的 css

选项卡未添加到 QTabWidget

片段选项卡未使用所有空间

卡未在引导程序 4 中居中 [重复]

选项卡中的顺风选项卡未按预期工作