Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
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?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

firewood

macrumors G3
Jul 29, 2003
8,113
1,352
Silicon Valley
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.


.
 

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
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.


.


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?
 

keehun

macrumors regular
Mar 17, 2008
110
0
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.
 

firewood

macrumors G3
Jul 29, 2003
8,113
1,352
Silicon Valley
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.

.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.