Peek/Pop Preview Ignores Cell Corner Radius in Collection View

update corner radius constraint in dynamically sized cell

A view's frame is not stored directly. It is computed from layer properties position, bounds.size, transform, and anchorPoint. What you're seeing here is that the system does not alter the frame using setFrame:.

Instead of setting cornerRadius in frame.didSet, override layoutSubviews to set it. The system schedules a call to layoutSubviews whenever a view's size changes (and in some other circumstances).

override func layoutSubviews() {
super.layoutSubviews()
cellImage.layer.cornerRadius = (frame.height * 0.75) / 2
}

UIProgressView corner radius changing when updating progress

The UIProgressView has it's own standard height and it's not really meant to be changed. When you set custom constraints you are probably breaking the original constraints the progress view has. Your custom corner radius is probably overridden every time the UIProgressView reloads it's layout with layoutSubviews() and sets it to 50% of whatever the current height is.

I see two solutions for this problem.

1. Custom Progress View (preferred)

This would be a preferred choice, simply create custom progress view and don't worry about breaking any constraints, and changing corners!

2. Keep fighting back

UIProgressView is probably changing its corners overytime layoutSubviews() is called so what you can do is to try to set it back to your desired values by overriding the method in your view/cell.

override func layoutSubviews() {
super.layoutSubviews()
greenBar.layer.cornerRadius = 0.2
redBar.layer.cornerRadius = 0.2
}

If this is not enough, try different places, like layoutIfNeeded() of prepareForReuse() etc.

An alternative to using a constraints for height, you could you a transform, but then the progress bar looks kinda funny at the sides.

// x: 1 - keeps the dimention the same size 
// y: 10 - makes the height 10x bigger
greenBar.transform = CGAffineTransform(scaleX: 1, y: 10)

The 2nd solution is not really a good advice since you will find yourself constantly fighting the original implementation. UIProgressView is not designed to be used the way you are using it so I strongly suggest, try solution 1 and implement your own view, where you set the rules :) Good luck!

Very Strange View Behavior When Implementing 3D Touch Preview

It took me a while to hunt this bug down. Turns out it's caused (in my case) by https://github.com/icanzilb/EasyAnimation. When I remove the library the bug is gone.

Cheers!

Edit: As it happens it's documented here: https://github.com/icanzilb/EasyAnimation/issues/14

Corner Radius on UIToolbar?

Add

self.layer.masksToBounds = true

to the view with the corner radius.



Related Topics



Leave a reply



Submit