我是tvOS的新手。我在Objective-C中使用XIB文件创建了UICollectionView。我如何关注UICollectionViewCell?
我在单元格中有一个标签和一个图像视图,我想要同时聚焦标签和图像视图。
答案 0 :(得分:12)
UICollectionViewCell
不是焦点外观,但您可以自行添加一个。
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
if (self.focused)
{
// Apply focused appearence,
// e.g scale both of them using transform or apply background color
}
else
{
// Apply normal appearance
}
}
OR
如果您只是想集中ImageView
,请在集合视图单元格获得焦点时进行缩放,您可以在awakeFromNib
方法中执行此操作
self.imageView.adjustsImageWhenAncestorFocused = YES;
self.clipToBounds = NO;
答案 1 :(得分:4)
app.factory('friendProfileService', ['$http', '$stateParams', function($http) {
return {
loadProfile: function(id) {
return $http.get('/users/'+ id +'json');
}
};
}])
答案 2 :(得分:2)
将以下方法添加到您的collectionview单元格。它将显示焦点单元格的标题,仅提供完整的焦点外观。
override func awakeFromNib() {
super.awakeFromNib()
// These properties are also exposed in Interface Builder.
imageView.adjustsImageWhenAncestorFocused = true
imageView.clipsToBounds = false
title.alpha = 0.0
}
// MARK: UICollectionReusableView
override func prepareForReuse() {
super.prepareForReuse()
// Reset the label's alpha value so it's initially hidden.
title.alpha = 0.0
}
// MARK: UIFocusEnvironment
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
/*
Update the label's alpha value using the `UIFocusAnimationCoordinator`.
This will ensure all animations run alongside each other when the focus
changes.
*/
coordinator.addCoordinatedAnimations({
if self.focused {
self.title.alpha = 1.0
}
else {
self.title.alpha = 0.0
}
}, completion: nil)
}