PDA

View Full Version : Problem with view only showing in background...




SunnyLi
Oct 15, 2010, 05:42 AM
Hi Guys,

I have a problem with one of my views, it has some squares drawn on it and you can only see it if you are switching a view say to go to settings so its right at the back.

i can change it in the appdelegate from this where it shows in the background:


MainView *view = [[MainView alloc] initWithFrame:[window frame]];
[window addSubview:view];
[view release];

mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];



To this but it then covers up the controls on the bottom of the screen:

mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];

MainView *view = [[MainView alloc] initWithFrame:[window frame]];
[window addSubview:view];
[view release];

[window makeKeyAndVisible];



dejo
Oct 15, 2010, 08:46 AM
What is the purpose of mainViewController and what is it's relationship to view?

SunnyLi
Oct 15, 2010, 09:08 AM
What is the purpose of mainViewController and what is it's relationship to view?

I have the mainviewcontroller which has all my buttons etc on and then this mainview which is used for drawing all the squares on.

dejo
Oct 15, 2010, 09:22 AM
I have the mainviewcontroller which has all my buttons etc on and then this mainview which is used for drawing all the squares on.
Again, I ask: what is the relationship between the two views? Is view some kind of background view to mainViewController's view? Clearly, if each view takes the entire window frame, they both cannot display at the same time (assuming they are both opaque).

SunnyLi
Oct 15, 2010, 09:47 AM
Again, I ask: what is the relationship between the two views? Is view some kind of background view to mainViewController's view? Clearly, if each view takes the entire window frame, they both cannot display at the same time (assuming they are both opaque).

Yeh thats what i wanted to do, have the squares drawn on the background of the mainviewcontroller. But in the drawing tutorial it showed me to do it this way with the drawing on a separate view.

dejo
Oct 15, 2010, 09:56 AM
But in the drawing tutorial it showed me to do it this way with the drawing on a separate view.
Which tutorial? Do you have a link?

SunnyLi
Oct 15, 2010, 10:14 AM
Which tutorial? Do you have a link?

It was this one

http://www.edumobile.org/iphone/ipad-development/draw-circle-triangle-and-rectangle-in-iphone/

Should it not be done that way?

dejo
Oct 15, 2010, 11:12 AM
Should it not be done that way?
If all you're doing is drawing circles, triangles and rectangles, it's fine. But it just overlaps the main (default) view with the custom one. The problem is you're now trying to add some UI elements for interactivity and for some reason you feel two separate views are necessary to implement it. It's possible but you need to rethink the relationship as well as the layering between the two views. But it's also possible to implement the concept using a single view.

SunnyLi
Oct 16, 2010, 02:36 AM
If all you're doing is drawing circles, triangles and rectangles, it's fine. But it just overlaps the main (default) view with the custom one. The problem is you're now trying to add some UI elements for interactivity and for some reason you feel two separate views are necessary to implement it. It's possible but you need to rethink the relationship as well as the layering between the two views. But it's also possible to implement the concept using a single view.

Could I just move all the drawing code from mainview to the mainviewcontoller?

robbieduncan
Oct 16, 2010, 03:39 AM
Could I just move all the drawing code from mainview to the mainviewcontoller?

Controllers don't draw. Views do.