Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift3 TVOS在镜头或焦点大小时调整图像_Swift3_Uiimageview_Tvos_Apple Tv - Fatal编程技术网

Swift3 TVOS在镜头或焦点大小时调整图像

Swift3 TVOS在镜头或焦点大小时调整图像,swift3,uiimageview,tvos,apple-tv,Swift3,Uiimageview,Tvos,Apple Tv,使用imgView.adjustSimageWhennancestorfocused=true进行对焦时,是否可以调整图像视图的大小/帧 一直在搜索网页,但找不到任何可以设置效果缩放大小的东西,似乎只是一些默认值。你似乎无法做到这一点。我认为苹果不允许这样做是有原因的 有很多。他们建议使用不同列数的网格布局的间距和项目大小,以便获得最佳的查看体验: 以下网格布局提供了最佳的查看体验。是 确保在未聚焦的行和列之间使用适当的间距来 防止项目聚焦时重叠 我猜聚焦的UIImageView的“默认”框架考

使用
imgView.adjustSimageWhennancestorfocused=true进行对焦时,是否可以调整图像视图的大小/帧


一直在搜索网页,但找不到任何可以设置效果缩放大小的东西,似乎只是一些默认值。

你似乎无法做到这一点。我认为苹果不允许这样做是有原因的

有很多。他们建议使用不同列数的网格布局的间距和项目大小,以便获得最佳的查看体验:

以下网格布局提供了最佳的查看体验。是 确保在未聚焦的行和列之间使用适当的间距来 防止项目聚焦时重叠

我猜聚焦的
UIImageView
的“默认”框架考虑了这些建议的项目大小。苹果公司不允许改变它,因为它可能会引起问题,就像其他网格项目重叠一样


因此,您不能修改聚焦的
UIImageView
的框架,但您可以间接访问它-通过使用
focusedFrameGuide

您似乎无法做到这一点。我认为苹果不允许这样做是有原因的

有很多。他们建议使用不同列数的网格布局的间距和项目大小,以便获得最佳的查看体验:

以下网格布局提供了最佳的查看体验。是 确保在未聚焦的行和列之间使用适当的间距来 防止项目聚焦时重叠

我猜聚焦的
UIImageView
的“默认”框架考虑了这些建议的项目大小。苹果公司不允许改变它,因为它可能会引起问题,就像其他网格项目重叠一样


因此,您不能修改聚焦的
UIImageView
,但可以间接访问它-通过使用
focusedFrameGuide

可以通过imgView.transform调整大小。如果您的IMG视图位于另一个视图内(例如位于
UICollectionViewCell
),则在接收焦点时,可以使用下面的代码将图像缩小10%

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    super.didUpdateFocus(in: context, with: coordinator)
    if context.nextFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = self.transform.scaledBy(x: 0.9, y: 0.9)
        }, completion: nil)
    }
    if context.previouslyFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = .identity
        }, completion: nil)
    }
}
此外,您还可以使用
adjustsImageWhenAncestorFocused=true计算
UIImageView
的系统焦点比例,使用下一个代码:

let xScale = imgView.focusedFrameGuide.layoutFrame.size.width / imgView.frame.size.width 
let yScale = imgView.focusedFrameGuide.layoutFrame.size.height / imgView.frame.size.height 
如果您想在聚焦于
UIImageView
时使用
adjustsImageWhenAncestorFocused=true
删除比例,请使用:

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    super.didUpdateFocus(in: context, with: coordinator)
    let xScale = imgView.focusedFrameGuide.layoutFrame.size.width / imgView.frame.size.width 
    let yScale = imgView.focusedFrameGuide.layoutFrame.size.height / imgView.frame.size.height 
    if context.nextFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = self.transform.scaledBy(x: 1 / xScale, y: 1 / yScale)
        }, completion: nil)
    }
    if context.previouslyFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = .identity
        }, completion: nil)
    }
}

注意:不要忘记在
UIImageView

上设置
clipsToBounds=false
,您可以通过imgView.transform调整大小。如果您的IMG视图位于另一个视图内(例如位于
UICollectionViewCell
),则在接收焦点时,可以使用下面的代码将图像缩小10%

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    super.didUpdateFocus(in: context, with: coordinator)
    if context.nextFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = self.transform.scaledBy(x: 0.9, y: 0.9)
        }, completion: nil)
    }
    if context.previouslyFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = .identity
        }, completion: nil)
    }
}
此外,您还可以使用
adjustsImageWhenAncestorFocused=true计算
UIImageView
的系统焦点比例,使用下一个代码:

let xScale = imgView.focusedFrameGuide.layoutFrame.size.width / imgView.frame.size.width 
let yScale = imgView.focusedFrameGuide.layoutFrame.size.height / imgView.frame.size.height 
如果您想在聚焦于
UIImageView
时使用
adjustsImageWhenAncestorFocused=true
删除比例,请使用:

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    super.didUpdateFocus(in: context, with: coordinator)
    let xScale = imgView.focusedFrameGuide.layoutFrame.size.width / imgView.frame.size.width 
    let yScale = imgView.focusedFrameGuide.layoutFrame.size.height / imgView.frame.size.height 
    if context.nextFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = self.transform.scaledBy(x: 1 / xScale, y: 1 / yScale)
        }, completion: nil)
    }
    if context.previouslyFocusedView === self {
        coordinator.addCoordinatedAnimations({
            self.imgView.transform = .identity
        }, completion: nil)
    }
}

注意:别忘了在
UIImageView

上设置
clipsToBounds=false
,我认为你应该自己实现它。我认为你应该自己实现它。