Autolayout is not resizing Uicollectionviewcell it

2019-04-16 16:32发布

I have a uicollectionview cell with an image view inside that I want to resize when I switch to a larger 'zoomed in' layout.

I have placed constraints inside the cell that does resize the image view when the zoomed in layout is displayed. I am using uicollectionview setLayout animated method.

The problem is the image does not scale with animation only the collection view cell does.

The image seems to just jump into its end size with no interpolation. So the animation looks extremely choppy.

It seems as if I need to somehow control the auto layout constraints so they animate with the set layout animated method but I don't know how.

Is there a proper way to scale the cell and it's contents ?

Thanks so much!

2条回答
女痞
2楼-- · 2019-04-16 16:52

I had (have) the same problem with Auto Layout!

Presently the simplest way I've found to deal with it is to set:

imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

This causes the imageView size transition to be animated smoothly and is the only thing that I've found to work consistently with setCollectionViewLayout:animated:

查看更多
我命由我不由天
3楼-- · 2019-04-16 16:59

You may find this answer and the linked GitHub demo app I wrote to solve a similar issue helpful.

查看更多
登录 后发表回答