vendredi 31 juillet 2015

Resizing Complex UIView with AutoLayout (Swift)

So I'm pretty new to AutoLayout, but more often than not I'm able to hack my views into shape or model off samples on the web.

However, I've created this rather complex view that just doesn't resize no matter what constraints I try.

Here are a few screenshots of what's going on.

The first shot is my Interface Builder layout. It's got a 4-corners kind of thing going on, with a UIImageView in each corner. In the center is a blurred VisualEffectView; it lays on top of the images. The layout was constructed with the parent view at 200x200

The second shot is a successful rendering at 200x200. As you can see, the 4 images load fine (yeah, I know they're a bit stretched, I just haven't handled their scaling code yet). Programmatically, I set the cornerRadius properties of both the parent view and the blurred view to 1/2 their width, so as to make them circular. Also programmatically, I added a label as a subview to the blurred view.

Then it all goes downhill. The third shot is my attempting to render the view at 250x250. The parent view renders well and maintains a circular shape, but just about everything else is wrong.

The most frustrating part is the UIImageViews, which all go haywire and extend their bounds even though I've set them to be equal widths.

The blurred view at least stays centered, but something isn't called which prevents its bounds.width property to be updated, which is what the cornerRadius is based off of.

The label doesn't stay center in the blurred view, despite setting its autoesizingMask to flexible all around.

Here is a snippet of my initialization code, which might be useful.

Any help that you all could provide would be greatly appreciated (even if it just fixes one of the several issues).

P.S. I apologize for the cats pics.

Edit: I achieved the desired result by writing the code manually and ditching Interface Builder and AutoLayout entirely.

Aucun commentaire:

Enregistrer un commentaire