I am very desperate -- every day I stare at this problem and I cannot get anywhere.
I need to create a large wheel. centre (0, 0), radius 1.0. on the rim of this wheel are several custom-drawn button controls.
a rectangle on the iPhone screen, say (10,10) - (320, 200) can 'see' some fraction of this wheel, say for example (0.5, 0.5) - (0.8, 0.7)
the wheel needs to rotate.
a bit like being able to look through one's bedroom window and seeing part of a fairground wheel as it rotates.
could someone help get me started?
(NOTE: I do not want to use interface builder, Mainly because every visual object will be drawn from code.)
I have created a sub view:
Code:
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
[super loadView];
CGRect frame = CGRectMake(10, 10, 320-10, 200-10);
myView* v = [ [ [myView alloc] initWithFrame:frame] autorelease];
v.clipsToBounds = YES;
[[self view] addSubview: v];
}
And have overridden the drawrect() of myView so that it draws a picture of the wheel ( placing buttons will come later ), and rotates.
Code:
- (void)drawRect:(CGRect)rect {
// Drawing code
// Get the graphics context and clear it
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
// Draw a red solid square
//CGContextSetRGBFillColor(ctx, 255, 0, 0, 1);
//CGContextFillRect(ctx, CGRectMake(10, 10, 50, 50));
CGRect r = CGRectMake(10,10,300,300);
UIImage* backgroundImage;
backgroundImage = [UIImage imageNamed:@"Horus2.jpg"];
[backgroundImage drawInRect:r];
CGImageRelease(backgroundImage.CGImage);
CGAffineTransform rotate = CGAffineTransformMakeRotation( 45.0 / 180.0 * 3.14 );
[self setTransform:rotate];
however, this is rotating the actual frame!!! this is no good! I want EVERYTHING to be rotated, not just the image. But I don't want the frame rotated. and I have no idea how to construct the coordinate system I want to work with.
Please could someone help me? I am floundering badly... I have already posted this problem, but wasn't able to understand the reply :/ please please say something I can understand. I cannot move on this project until I have got past this hurdle, and I cannot do it. It is sapping my will to live :/
Sam