Clipstobounds Causes Uiimage to Not Display in iOS10 & Xcode 8

clipsToBounds causes UIImage to not display in iOS10 & XCode 8

I had the same problem and calling layoutIfNeeded before all the rounded corner / clipsToBounds stuff fixed the issue. iOS 10 GM with xcode 8 GM causes views to disappear due to roundedCorners & clipsToBounds

iOS 10 GM with xcode 8 GM causes views to disappear due to roundedCorners & clipsToBounds

I am not sure if this is a new requirement, but I solved this by adding [self layoutIfNeeded]; before doing any cornerRadius stuff. So my new custom awakeFromNib looks like this:

- (void)awakeFromNib {
[super awakeFromNib];
[self layoutIfNeeded];
self.tag2label.layer.cornerRadius=self.tag2label.frame.size.height/2;
self.tag2label.clipsToBounds=YES;
}

Now they all appear fine.

iOS 10 GM with xcode 8 GM causes views to disappear due to roundedCorners & clipsToBounds

I am not sure if this is a new requirement, but I solved this by adding [self layoutIfNeeded]; before doing any cornerRadius stuff. So my new custom awakeFromNib looks like this:

- (void)awakeFromNib {
[super awakeFromNib];
[self layoutIfNeeded];
self.tag2label.layer.cornerRadius=self.tag2label.frame.size.height/2;
self.tag2label.clipsToBounds=YES;
}

Now they all appear fine.

UICollectionView not showing images in iOS 10

Set collection view's isPrefetchingEnabled property to false (by default it's true in iOS 10).

Since Xcode 8 and iOS10, views are not sized properly on viewDidLayoutSubviews

Now, Interface Builder lets the user change dynamically the size of every view controllers in storyboard, to simulate the size of a certain device.

Before this functionality, the user should set manually each view controller size. So the view controller was saved with a certain size, which was used in initWithCoder to set the initial frame.

Now, it seems that initWithCoder do not use the size defined in storyboard, and define a 1000x1000 px size for the viewcontroller view & all its subviews.

This is not a problem, because views should always use either of these layout solutions:

  • autolayout, and all the constraints will layout correctly your views

  • autoresizingMask, which will layout each view which doesn't have any constraint attached to (note autolayout and margin constraints are now compatible in the same view \o/ !)

But this is a problem for all layout stuff related to the view layer, like cornerRadius, since neither autolayout nor autoresizing mask applies to layer properties.

To answer this problem, the common way is to use viewDidLayoutSubviews if you are in the controller, or layoutSubview if you are in a view. At this point (don't forget to call their super relative methods), you are pretty sure that all layout stuff has been done!

Pretty sure? Hum... not totally, I've remarked, and that's why I asked this question, in some cases the view still has its 1000x1000 size on this method. I think there is no answer to my own question. To give the maximum information about it:

1- it happends only when laying out cells! In UITableViewCell & UICollectionViewCell subclasses, layoutSubview won't be called after subviews would be correctly layed out.

2- As @EugenDimboiu remarked (please upvote his answer if useful for you), calling [myView layoutIfNeeded] on the not-layed out subview will layout it correctly just in time.

- (void)layoutSubviews {
[super layoutSubviews];
NSLog (self.myLabel); // 1000x1000 size
[self.myLabel layoutIfNeeded];
NSLog (self.myLabel); // normal size
}

3- To my opinion, this is definitely a bug. I've submitted it to radar (id 28562874).

PS: I'm not english native, so feel free to edit my post if my grammar should be corrected ;)

PS2: If you have any better solution, feel free not write another answer. I'll move the accepted answer.

Xcode 8 UIButtons with constraints not showing up

I was missing the point of setting UIButton class to my custom class. I checked my custom class and have seen that I set corner radius on awakeFromNib() method. I called layoutIfNeeded() before I set corner radius which was the solution in my case.

Creating an image format with an unknown type is an error with UIImagePickerController

Below mentioned code did solve the problem for me -

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imagePost.image = image
} else{
print("Something went wrong")
}

self.dismiss(animated: true, completion: nil)
}


Related Topics



Leave a reply



Submit