Reputation: 3977
I am having a strange problem here. I have a UIScrollView that is setup in the interface builder. I add content to it via a method called setupScrollView which is as follows :
-(void)setupScrollView {
UIView *content = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width*[self.stickers count], self.scrollView.frame.size.height)];
for(int i=0; i<[self.stickers count]; i++){
UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectMake(i*self.scrollView.frame.size.width, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
MySticker *sticker = self.stickers[i];
imageView.image=sticker.image;
[content addSubview:imageView];
NSLog(@"scroll view width is %f",self.scrollView.frame.size.width);
NSLog(@"ImageView width is %f", imageView.frame.size.width);
}
self.scrollView.contentSize=CGSizeMake(content.frame.size.width ,content.frame.size.height);
[self.scrollView addSubview:content];
}
Now I call this method in viewDidLayoutSubviews
because I need the views to be repositioned first after using the constraints set in the interface builder. This all works fine but my images in the scroll view are slightly distorted with jagged edges, there are sticker/chat images with black outlines so it's quite noticeable. If however I place the [self setupScrollView] in the viewDidLoad method the images won't be distorted and look perfectly clear. Example image:
Have no idea why it is doing this. Could anyone give me some pointers to what I might be doing wrong?
Upvotes: 1
Views: 123
Reputation: 161
If it works correctly in viewDidLoad try to call setupScrollView method in viewWillLayoutSubviews method. Also check situation when setupScrollView will be call more than once to avoid adding duplicates.
Upvotes: 1