【问题标题】:AppleTV focused image border does not scaleAppleTV 聚焦图像边框不缩放
【发布时间】:2016-12-23 10:36:53
【问题描述】:

我正在制作一个 tvOS 应用程序。我有一个集合视图单元,它有一个 UIImageView。我在界面构建器中选中“聚焦时调整图像”,这样我就可以使用系统为图像提供的聚焦效果。问题是我还在为图像设置边框。当视图获得焦点并且图像放大时,边框不会随图像放大。任何想法如何在视图聚焦时更新边框的尺寸?

【问题讨论】:

    标签: swift uicollectionviewcell tvos


    【解决方案1】:

    我认为你应该把你的 imageView 放在 UIView 的对象中,然后给这个视图加上边框。之后,您应该重写“didUpdateFocus”方法并根据需要制作动画。 看, 就我而言,我已将 imageView 放入“viewBg”对象并为该对象提供动画。

    在你的课堂上:

    func viewAnimation(view:UIView , isNormal:Bool)
    {
        UIView.animate(withDuration: 0.5, animations: { () -> Void in
            if isNormal{
                view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0);
            }
            else{
                view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3);
            }
    
            })
        { (finished) -> Void in
    
        }
    }
    
    override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
        if(context.previouslyFocusedView != nil)
        {
            if (context.previouslyFocusedView is testCell)
            {
                let cell:testCell = context.previouslyFocusedView as! testCell
                self.viewAnimation(view: cell.viewBg, isNormal: true)
            }
        }
        if(context.nextFocusedView != nil)
        {
            if (context.nextFocusedView is testCell)
            {
                let cell:testCell = context.nextFocusedView as! testCell
                self.viewAnimation(view: cell.viewBg, isNormal: false)
            }
        }
    }
    

    在您的 CollectionViewCell 方法中:

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:testCell = collectionView.dequeueReusableCell(withReuseIdentifier: "testCell", for: indexPath) as! testCell
        cell.imgIcon.image  = UIImage(named:arrayIconImages.object(at: indexPath.row) as! String)
        cell.viewBg.layer.borderColor = UIColor.black.cgColor
        cell.viewBg.layer.borderWidth = 10.00
        return cell
    }
    

    所以,通过这种方式,您可以在图像视图中提供带边框的动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-17
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      相关资源
      最近更新 更多