Reputation: 2383
I'm working on a calendar app and i have a lot of view-s in in each page of the scrollview. The problem is that on simulator it works well but when i install the app on device the swiping between pages is very laggy.
I notice that a lot of time is taking buy:
masksToBounds
- i need to have some circle view-s addSubview
- there are a lot of themand draw all views in drawRect
involve to change all the methods and order and also there will be different behaviour on resize.
The Question is how can i fix the lag ? is drawRect
better then subviews ?
Upvotes: 1
Views: 40
Reputation: 2383
The solution that i came up is to have a container where i place all the views then i convert that view to the UIImage
and from 20 UIView
's i manage to reduce to one UIImageView
I use this method for getting the image from UIView:
- (UIImage *)snapShotForView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Upvotes: 0
Reputation: 38162
I can suggest you an alternative. I've recently developed a calendar based iOS application and had used this already available FSCalendar tool. This works pretty smooth on simulator & device while scrolling across month views.
So, you might want to try this out!
Upvotes: 2