Swift AppleTV聚焦图像边框不缩放

Swift AppleTV聚焦图像边框不缩放,swift,uicollectionviewcell,tvos,Swift,Uicollectionviewcell,Tvos,我正在制作一个tvOS应用程序。我有一个集合视图单元格,它有一个UIImageView。我在界面生成器中选中“对焦时调整图像”,以便可以使用系统提供的图像对焦效果。问题是我还在为图像设置边框。当视图获得焦点且图像放大时,边框不会随图像放大。你知道当视图聚焦时如何更新边框的尺寸吗?我认为你应该把你的imageView放在UIView的对象中,然后给这个视图加上边框。之后,您应该重写“didUpdateFocus”方法,并根据需要制作动画。 看见 在我的例子中,我将imageView放在“viewB

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

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

在你们班: 在CollectionViewCell方法中:
因此,通过这种方式,您可以在图像视图中提供带有边框的动画。

我认为您应该将您的图像视图放在UIView的对象中,然后为该视图提供边框。之后,您应该重写“didUpdateFocus”方法,并根据需要制作动画。 看见 在我的例子中,我将imageView放在“viewBg”对象中,并为该对象提供动画

在你们班: 在CollectionViewCell方法中: 所以,通过这种方式,您可以在图像视图中提供带边框的动画

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