I have a method that creates a mask layer based on the current frame of my UIImageView, which works as I expected. However, in one case, I modify the height constraint of a UIImageView in the viewWillAppear method, and then apply the mask creator to the UIImageView, which creates a mask with a worng size. So my question is, how can I force to get the modified correct frame of that UIImageView?
Right now I'm getting the height 140 insted of 105, but if I use layoutIfNeeded after setting the constraint it become 118, which is closer, but still not 105.
Updated:
The method that I use for creating the mask:
public func setupMaskForImageView() {
let mask = CALayer()
let resizedMaskImage = resizeImage(UIImage(named: imageMaskName)!, newSize: frame.size)
mask.contents = resizedMaskImage
mask.frame = CGRectMake(0, 0, frame.size.width, frame.size.height)
layer.mask = mask
layer.masksToBounds = true
}
and I modified the constraint in viewWillAppear with
imageHeight.constant = UIScreen.mainScreen().bounds.width / 2.5
layerand theimageView. Did you mean that thelayerframe is not equal to theimageView's?imageViewandlayer. The only thing I can tell is that you need a way to know when yourimageViewframe changed and notify to updatelayer's frame. I suggest you updatelayer's frame inviewDidLayoutSubviewsof your view controller