在UICollectionView的cell中添加subView不显示的问题

在cellForItemAtIndexPath方法中
var videoView = videos["video"] as UIView
videoView.frame = cell.frame
self.collectionView.addSubview(videoView)

如果我设置了 videoView.frame = cell.frame 这句,那么这个subview 就不会显示

我修改了frame(包含在cell中)

var videoView = videos["video"] as UIView
videoView.frame = videoView.frame = CGRect(x: 37, y: 94, width: 100, height: 100)
self.collectionView.addSubview(videoView)

这样就显示了

请问这是什么原因?

阅读 9.4k
3 个回答

videoView.frame = cell.framecell.frame打印出来看看不就知道啦~

在cellForItemAtIndexPath处设置断点,检查cell.frame是否是你预期的。不过话说为什么不用auto layout

新手上路,请多包涵

需要重写initWithFrame:方法

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题