Constantin Saulenco
Constantin Saulenco

Reputation: 2383

View stack or Drawing

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:

and 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

Answers (2)

Constantin Saulenco
Constantin Saulenco

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

Abhinav
Abhinav

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

Related Questions