1. Welcome to the new MacRumors forums. See our announcement and read our FAQ


Discussion in 'iPhone/iPad Programming' started by sujithkrishnan, Dec 1, 2008.

  1. macrumors 6502

    Hi all,
    i have drawn ellipse in my view,when user touches within that ellipse i should go on drawing eclipse with increasing radius.How to achive this.CGContextRef doesn't work when i try to re draw the ellipse in buttonPressed event

    We can call setNeedsDisplay, but it will call the drawRect with old parameters (radius1 and radius2), how to pass new radius to drawRect and draw the ellipse?
  2. Moderator


    Staff Member

    1) Whilst this makes no difference I think you mean ellipse, not eclipse

    2) Where are you getting this CGContextRef from? If you are trying to draw outside of your drawRect: method, or calling drawRect: directly instead of calling the correct method to ask the view to redraw this is probably the issue.
  3. macrumors 603

    Unlike other programming environments with direct graphics calls, in CocoaTouch, you don't draw directly when you want to.

    Instead, you tell the OS you need to draw (using the setNeedsDisplay method on the view that needs drawing, then exit your current method back to the run loop). When the OS decides it's time to draw, it will call that view's drawRect method, and then that method can draw in the context it's given.

    The basic paradigm for a lot of Cocoa is that your program doesn't call the OS. Instead, you make your program a bunch of modules that the OS calls when it's good and ready.

  4. macrumors 6502


    Prob is that we need a context to push to the stack. In case of drawRect OS will do that, If we want to do it manually, options are there some CGContextPush / CGCOntextPop methods are there.
    I just want to know how to make use of that?
  5. macrumors regular

    I think a better way would be subclass a UIView and draw directly in that. Then add the subclass as a subview. UIView has very good added bonus, like touch handling, etc.
  6. macrumors 603

    If you are trying to get a context to draw inside your buttonPressed handler, you haven't yet learned the CocoaTouch paradigm. It is not guaranteed that the graphics chip is accessible at all by the CPU inside CocoaTouch UI event handlers.

    Decide what you need to draw, update your parameters, exit your button handler, and then draw later when drawRect gets called.


Share This Page