UIView drawRect will update whole bounds

  • Hi all,
    I implement drawRect of a subclass of UIView. I found view will update whole bounds when I switch from another app to myapp. Because I draw a cgimage on the view's bounds, it cost lots of time. Are there some properties of view or layer to make the update rect not to be whole bounds?
  • Can you just set the CGImage as the .contents of the view's layer?

    --Kyle Sluder

    On May 15, 2013, at 3:42 AM, li shunnian <sonofsky2010...> wrote:

    > Hi all,
    > I implement drawRect of a subclass of UIView. I found view will update whole bounds when I switch from another app to myapp. Because I draw a cgimage on the view's bounds, it cost lots of time. Are there some properties of view or layer to make the update rect not to be whole bounds?
  • Or even more simply just use a UIImageView.

    On May 15, 2013, at 9:36 AM, Kyle Sluder <kyle...> wrote:

    > Can you just set the CGImage as the .contents of the view's layer?
    >
    > --Kyle Sluder
    >
    > On May 15, 2013, at 3:42 AM, li shunnian <sonofsky2010...> wrote:
    >
    >> Hi all,
    >> I implement drawRect of a subclass of UIView. I found view will update whole bounds when I switch from another app to myapp. Because I draw a cgimage on the view's bounds, it cost lots of time. Are there some properties of view or layer to make the update rect not to be whole bounds?


    --
    David Duncan
  • My app is a painter, the image is used for back buffering. When dragging, I calculate the points between the previous point and now point, and draw a small image on the back buffer image. Then update the back buffer image to the view.
  • On 16/05/2013, at 11:29 AM, li shunnian <sonofsky2010...> wrote:

    > I implement drawRect of a subclass of UIView. I found view will update whole bounds when I switch from another app to myapp. Because I draw a cgimage on the view's bounds, it cost lots of time. Are there some properties of view or layer to make the update rect not to be whole bounds?

    > My app is a painter, the image is used for back buffering. When dragging, I calculate the points between the previous point and now point, and draw a small image on the back buffer image. Then update the back buffer image to the view.

    I can't see you have any choice - at times the view will need to refresh its whole bounds, and if that means drawing the whole image, you will have to do that, or else end up with blank areas which I'm sure you don't want. If the view is within a scroller, then it should only ever refresh the visible portion.

    If it's slow, perhaps you ought to investigate why. Are you scaling or transforming the image? How do you do the drawing? Show code.

    --Graham
  • Not that this answers your question, but as graham eluded to, there aren't a lot if choices. I'd look into showing a progress indicator or look into tiling. GL

    Please excuse mobile typos

    On May 15, 2013, at 6:44 PM, Graham Cox <graham.cox...> wrote:

    >
    > On 16/05/2013, at 11:29 AM, li shunnian <sonofsky2010...> wrote:
    >
    >> I implement drawRect of a subclass of UIView. I found view will update whole bounds when I switch from another app to myapp. Because I draw a cgimage on the view's bounds, it cost lots of time. Are there some properties of view or layer to make the update rect not to be whole bounds?
    >
    >> My app is a painter, the image is used for back buffering. When dragging, I calculate the points between the previous point and now point, and draw a small image on the back buffer image. Then update the back buffer image to the view.
    >
    >
    > I can't see you have any choice - at times the view will need to refresh its whole bounds, and if that means drawing the whole image, you will have to do that, or else end up with blank areas which I'm sure you don't want. If the view is within a scroller, then it should only ever refresh the visible portion.
    >
    > If it's slow, perhaps you ought to investigate why. Are you scaling or transforming the image? How do you do the drawing? Show code.
    >
    > --Graham
  • I found even in a very simple painter app,  view will refresh whole bounds when switching from another app.

    --
    Shunnian
  • On May 15, 2013, at 11:50 PM, li shunnian <sonofsky2010...> wrote:

    > I found even in a very simple painter app,  view will refresh whole bounds when switching from another app.

    This is expected, when your application is placed in the background, all of the backing stores for its views are discarded to save memory.

    >
    > --
    > Shunnian

    --
    David Duncan
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today