[iPhone] Simple UIView question

Hi,
I am trying to figure out why iPhone is behaving this way and I can not figure it out.
For testing, I am trying to display 3 views one on top of the other (using UIViewControllers). The problem is that except for the first one that goes directly on top of the window object, the rest of the views display about 20 pixels bellow the top of its superview
My very-very simple application, my delegate code is like this:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
UIViewController *viewController;
UIViewController *viewController2;
UIViewController *viewController3;
// Create the first ViewController and assign green to its view background color
viewController = [[UIViewController alloc] init];
[[viewController view] setBackgroundColor:[UIColor greenColor]];
// Create the second ViewController and assign purple to its view background color
viewController2 = [[UIViewController alloc] init];
[[viewController2 view] setBackgroundColor:[UIColor purpleColor]];
// Create the third ViewController and assign cyan to its view background color
viewController3 = [[UIViewController alloc] init];
[[viewController3 view] setBackgroundColor:[UIColor cyanColor]];
// Add view2 to view and view3 to view2
[[viewController view] addSubview:[viewController2 view]];
[[viewController2 view] addSubview:[viewController3 view]];
// Set background window color to red
[window setBackgroundColor:[UIColor redColor]];
// Add view to window
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
This displays about 20px of green at the top (from view), below that about 20px of purple (from view2) and the rest of the screen is cyan.
The question is why it is behaving like this and not display the views directly one on top of the other so at the end to show the screen in cyan (from view3 that is the last view added).
I do understand that there are different ways to do this but this is not the point here. I am try to understand why using this way, the iPhone behaves like this.
Thanks for your help.

The window frame is normally set to the bounds of the screen, (0, 0, 320, 480), regardless of whether the status bar is visible. I may have over-simplified my last reply, since this thread is really all about the status bar, which is 20 high. When the status bar is visible, a view controller created in code will have a view with a frame of (0, 20, 320, 460). However, when the status bar is hidden, the very same code will create a view with a frame of (0, 0, 320, 480). The taller view would also work with a visible status bar (since the bar is always on top), but the system is just trying not to waste the upper 320 x 20 area of the view.
Anyway, the coordinate system of the window is the same as that of the screen. So when the origin of the root view frame is (0, 20) there's no offset. I.e. the point (0, 20) relative to the window is also (0, 20) relative to the screen.
But when a second view with a (0, 20) frame origin is added to the first, the point (0, 20) is relative to the root view rather than the window. The point (0, 0) in the root view's system is the point (0, 20) in the window's system, so the point (0, 20) in the root view's system is (0, 40) in the window's system.
It might help to remember that every view object has both a frame property and a bounds property. The frame is defined in the coordinate system of the superview. The bounds is in the object's own coordinate system. So we can expect the origin of the bounds to always be (0, 0). I.e. the upper left corner is always in the same place when you're inside the view. But from outside the view, in the superview, you see the object's frame. The origin of the frame could be anywhere relative to the superview.
When a subview is added, its frame is given in the superview's coordinate system. So if the origin of the subview's frame is (0, 0), that means its upper left corner is in the same place as the superview's upper left corner. But the superview's upper left corner could be at the point (100, 200) on the screen.
Not sure if it will confuse you even more than the above, but try adding this line at the top of the code you posted:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
- Ray

Similar Messages

  • I know that iCloud backs-up apps and other stuff to your phone incase you want restore from a back-up if you start a New iPhone. My question is if I start a new iPhone (not use the restore from back-up option) and redownload apps like (games, Instagram),

    I know that iCloud backs-up apps and other stuff to your phone incase you want restore from a back-up if you start a New iPhone. My question is if I start a new iPhone (not use the restore from back-up option) and redownload apps like (Games, Instagram), would my pics show up on Instagram and would my Games show it was saved and the acccomplisments will remain from the last place I left out.

    Davin12 wrote:
    I know that iCloud backs-up apps and other stuff to your phone incase you want restore from a back-up if you start a New iPhone. My question is if I start a new iPhone (not use the restore from back-up option) and redownload apps like (Games, Instagram), would my pics show up on Instagram and would my Games show it was saved and the acccomplisments will remain from the last place I left out.
    Icloud or itunes backup, only backs up app data, not the app itself.
    so if you restore as new, then there is no app data on your phone, you start out new...

  • Simple/silly question: how do I set/change default font/color for outgoing mail messages?

    Simple/silly question: how do I set/change default font/color for outgoing mail messages?

    Just a suggestion..........
    Download Thunderbird.  Easier to use when it comes to what you want to do w/your emails. 

  • 4 Simple Flash Questions that Are Stumping Me!

    What is the Frame Rate for Web Animations
    Q1. I am making an animation which will be played on the web. What is the default frame rate (fps) of Flash CS5? And what is the frame rate of for web?
    Q2. My animation needs to be 30 seconds long. So at 15 fps that would mean I need to use 600 frames in Flash?
    How Do I Mask everything so all I see is the Content on the Stage?
    I have a wide image that extends past my movies stage size so when I preview my movie the image is visible. How do I mask out anything that extends past my movies window size? I believe I can create a layer named "mask" and place it above all other layers, but I forget how to make the mask. Any help is appreciated.
    How to Fade a Graphic
    I have a graphic element (some type) and I want it to fade from 0% to 100%. In older versions of Flash I could just select the symbol and then set it's alpha value to 0%, move a few keyframes and then set the alpha to 100%. Voila! but now it doesn't seem to work that way. How can I do this in CS5?

    Ned, it says 24 fps which means there is 24 frames per second so each 24 frames is 1 second.
    Date: Fri, 4 Nov 2011 05:35:16 -0600
    From: [email protected]
    To: [email protected]
    Subject: 4 Simple Flash Questions that Are Stumping Me!
        Re: 4 Simple Flash Questions that Are Stumping Me!
        created by Ned Murphy in Flash Pro - General - View the full discussion
    1 You can create your character as a movieclip and copy/paste that movieclip from one file to another. 2. One way to create a movieclip is to copy all the frame of the animation's timeline (select them all, right click the selection, choose Copy Frames), then create a new movieclip symbol (Insert -> New Symbol...etc) right click on its only keyframe and chhose Paste Frames.  THat will put all the layers and frames you copied into the movieclip The only way to come close to being certain about the timing of you animation is to use code to keep track of the time, something like getTimer()..  The frame rate that a file plays at is not a reliable means of dictating the time it takes due to a variety of factors which include the amount of content you are trying to process and performance limits of the user's machine.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4007420#4007420
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4007420#4007420. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Flash Pro - General by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Simple performance question

    Simple performance question. the simplest way possible, assume
    I have a int[][][][][] matrix, and a boolean add. The array is several dimensions long.
    When add is true, I must add a constant value to each element in the array.
    When add is false, I must subtract a constant value to each element in the array.
    Assume this is very hot code, i.e. it is called very often. How expensive is the condition checking? I present the two scenarios.
    private void process(){
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
             if (add)
             matrix[i][ii][iii][...]  += constant;
             else
             matrix[i][ii][iii][...]  -= constant;
    private void process(){
      if (add)
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
             matrix[i][ii][iii][...]  += constant;
    else
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
           matrix[i][ii][iii][...]  -= constant;
    }Is the second scenario worth a significant performance boost? Without understanding how the compilers generates executable code, it seems that in the first case, n^d conditions are checked, whereas in the second, only 1. It is however, less elegant, but I am willing to do it for a significant improvement.

    erjoalgo wrote:
    I guess my real question is, will the compiler optimize the condition check out when it realizes the boolean value will not change through these iterations, and if it does not, is it worth doing that micro optimization?Almost certainly not; the main reason being that
    matrix[i][ii][iii][...]  +/-= constantis liable to take many times longer than the condition check, and you can't avoid it. That said, Mel's suggestion is probably the best.
    but I will follow amickr advice and not worry about it.Good idea. Saves you getting flamed with all the quotes about premature optimization.
    Winston

  • I just upgraded my mac to Mountain Lion and turned on iCloud. Now all of the music stored on my mac shows up on my iphone. My question is, if I listen to this music on my iphone am I using up my data plan?

    I just upgraded my mac with Mountain Lion and turned on iCloud. Now all of the music stored on my mac shows up on my iphone. My question is, if I listen to this music on my iphone am I using up my data plan?

    No, if you are using the Music app you are playing them on your iPhone.

  • A few simple Logic questions...please help.

    I have a few probably simple Logic questions, that are nonetheless frustrating me, wondering if someone could help me out.
    1. I run Logic 8, all of the sounds that came with logic seem to work except organ sounds. I can't trigger any organ sounds (MIDI) on Logic, they won't play. I have a Yamaha Motif as my midi controller.
    Any idea why?
    2. I've starting running into a situation where I will record a MIDI track, the notes are recorded but they won't playback. The only track effected is the one that was just recorded. All other midi tracks playback.
    I have to cut the track, usually go out of Logic and back in, re record for it to playback properly. Any idea why this may be happening?
    3. How important is it to update to Logic 9. Are there any disadvantages down the road if I don't upgrade. If I purchase the $200 upgrade, do I get a package of discs and material, or it just a web download.
    Any help is appreciated!
    Colin

    seeren wrote:
    Data Stream Studio wrote:
    3) You get a full set of disks and manuals.
    They're including manuals now?
    I think his referring to the booklets ...on how to install etc
    It would be great to see printed manuals though ...I love books especially Logic/Audio related !!
    A

  • HT1296 i have iphone 4s, my question is how i can transfer MY DOCUMENTS fro my pc to my iphone 4s

    Respected sirs,
    kindly let me know the following:
    i have iphone 4s, my question is how i can transfer MY DOCUMENTS fro my pc to my iphone 4s
    my regards
    Talal DIAB

    http://ismashphone.com/2009/06/how-to-transfer-files-between-your-computer-and-i phone.html
    Note that these applications are not free.

  • Simple Quick Question

    wrong section, post was moved.
    Message was edited by:
    Rob17

    you titled "simple quick question"...
    .. complicated to answer..
    a) the TermsOfUse of the iTS don't allow any processing of purchased files, these are "copy protected"..
    b) iM has a voice-over function..
    c) iM is a video-edit app.. easy to use... just learn to handle it...
    d) iM allows to "extract" audio (=muting the original audio, adding your own..)
    e) to learn iM, spend some time here: http://www.apple.com/ilife/tutorials/imovie/index.html
    f) use pencil and paper first! WRITE and scribble, what shall happen when in your movie/parody... make a script, draw a storyboard .. THEN launch iM.. in other words: think first, then edit.. iM is just a tool, it does not "create"... Picasso needed a papertowel and half a stencil to create art....
    g) to get comfortable with iM, start with your own, small, short (3min!) project... import some stills, edit them, add a funny voice-over, add sounds, add music... good? make a bigger one...
    h) .. in our Lecture II, we teach you how to import shows from TV, youtube, wherever..
    standard disclaimer:
    be nice to ©opyrights ...

  • Hello I installed the latest version of iOS 6.0 on my iPhone 4s, my question is if I can come to is install iOS 5.1.1 Scroll Previous thank you

    helle i installed the latest veriosn of iOS 6.0 on my iPhone 4s , my questionis if i can come to is install iOS 5.1.1 scroll previous thanks

    you cannot downgrade the iOS at all. 

  • Simple query question

    hi all,
    I have a XMLType table with one column - I have presently one row, in my column xmlsitedata I have stored one large xml file.The schema definition is given below:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    - <xs:element name="siteList">
    - <xs:complexType>
    - <xs:sequence>
    <xs:element name="site" type="siteType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    - <xs:complexType name="siteType">
    - <xs:sequence>
    <xs:element name="nameEn" type="xs:string" />
    <xs:element name="nameFr" type="xs:string" />
    </xs:sequence>
    <xs:attribute name="code" type="xs:string" />
    </xs:complexType>
    </xs:schema>
    I have executed the query below:
    select x.XMLSITEDATA.extract('/siteList/site/nameEn/text()').getCLOBVal() "stName" from wsitelist x;
    and I get all english names of some 200 locations, however, there is 1 row selected and all names show up on one row. How do I split them into 200 or whatever rows?
    Thanks,
    Kowalsky

    Have a look at the answer provided in the following thread.
    very simple XML question
    This may solve your problem.
    use xmlsequence.
    Alvinder

  • SUPER SIMPLE DUMB Question about hard-wired desktop mac and wifi for iPhone

    Sorry if this has been already answered a million times. I have a desktop mac with a cable modem ethernet internet connection. I want to leave this hard-wired and setup a wifi network for a laptop or iPhone. What's the cheapest easiest way to do this?? I've never done anything wireless before.

    Could I just somehow split the feed from the the cable modem or ethernet cable and route part of it into an AirPort express??
    Unfortunately, no. This would create "confusion" for the modem as it is only expecting a single device to be connected to it. To be able to support both wired & wireless clients, you would need an Internet router with a built-in Ethernet switch, like the AirPort Extreme Base Station. If cost is an issue, you do NOT have to use an Apple router. There are a number of other vendors, like Belkin, D-Link, Linksys, & Netgear, to name a few, that offer similar models.

  • 2 iphones single PC questions from a yet to be iphone4 noobie

    Hi everyone.
    I have a series of questions regarding sync issues and hope I will not be too much of a hassle.
    I ordered 2 iphone4 devices for me and my wife due to arrive this weekend. While waiting for them, I started to research on possible problematic issues checking almost every possible topic on Google, downloaded the iphone4 guide and read thru and still got stuck with syncing.
    _Below is a summary of what I've done._
    *MAIN :* We have 2 Nokia phones and want to use my Mac Mini to handle all syncs for both.
    *iTunes :* We both have separate accounts. She never used hers, just getting ready.
    Apps: I downloaded some apps with mine, she didn't and we will be using a number of same apps.
    *Media :* We probably will load only pictures on our iphones. Definitely no music.
    *Contacts :* No Mobile Me. I synced my contacts via iSync to Address Book to combine with Entourage. With Adress Book, I tried to create 2 separate groups for each phone. Messed around with Address Book, got all my contacts deleted from Address Book AND phone.
    The only backup I had was in my wife's netbook (XP) back from September. Reloaded them, missing all additions in between, got cold feet and stopped syncing all together.
    _What I have learned from my research & my questions:_
    1) As far as I know, the best solution is to create a separate account for my wife with my Mac. She will only use my PC to sync. (Doesn't want to do it with her netbook because she will get a Mac Book in 2 months and doesn't want to hassle with it) Is creating a separate account the best way to go or is there a simpler solution?
    2) When we are syncing via iTunes, I will disable auto sync. Both iphones will have their separate distinctive names and I can separate the apps to be transferred to each phone. Is this correct?
    3) Now with contacts, I am scared to death. From what I know, I need to transfer the contacts to Address Book, sync w/ Entourage and load them on the new phones via iTunes.
    Biggest question is how do I separate the two separate databases? Do I create 2 groups in Address Book? If so, how do I create different contact databases in Entourage, merge them with the corresponding groups from Address Book to create 2 separate combined datagroups to be synced to each iphone?
    Also, how do I define iTunes settings to retrieve these separate datas from Entourage?
    Sorry to keep this post long and I hope that I've been able to explain my concerns clearly.
    Thank you in advance for your time and concern.
    Sincerely

    deggie - One last question.
    New user account is set. iTunes settings on both accounts are ready. Existing phone contacts are synced with relevant Address Books and backed up in the netbook. Looks like we are good to go for the iphones. Except libraries.
    Before I opted for the double user option, I created a 2nd iTunes library for my wife and downloaded her applications there.
    Now, when I log into my wife's account and open iTunes, the apps section is empty. I click Preferences/Advanced and try to change the location for iTunes files, but Mac won't allow me. The folder that has wife's iTunes library is marked with a no-entry sign and doesn't allow me to choose it.
    I logged back to my account, went Music/iTunes 2 (wife's library) then right-clicked, chose Get Info, checked shared folder option. Then logged in to wife's account and tried to change the library location again. Still that red no-entry sign.
    How can I move her apps to her new iTunes library?

  • Iphone gmail/email question

    Hello there,
    I was wondering if someone could answer a question for me. I have two email accounts set up on my 3G iphone. The Gmail account is set up and works fine. I was wondering if there was a way to avoid my emails (sent, inbox or otherwise) to NOT be deleted from my account......but only deleted from my phone....if that makes sense? If I delete anything to do with Gmail on the phone, it also is deleted from the entire account. Is there a way around this?
    When I use my standard pop3 account, I can delete all the emails on the phone when read or dealt with but they still come down on to my mac as normal. It's just the Gmail I was trying to figure out.
    So: When deleted from the phone......I can still access them when at home online.
    Thanks in advance for any suggestions.

    I asked something similar in another thread (http://discussions.apple.com/message.jspa?messageID=7758665#7758665) but it's still not working the way I need it to.
    For me,I need to delete emails from the phone, but leave them on my server; I set it up as POP, but then all the emails I sent were also downloaded to the phone, and I send out about 100 emails a day, so that doesn't work for me. I deleted that and set it up as IMAP, but now, like you, when I delete a message from my iPhone, it no longer appears in my gmail inbox on my computer, it's in All Mail.
    I don't have time to check different places for my mail--I had a Blackberry before the iPhone and it seemed so simple, so I need to figure out how to streamline it on the iPhone too!

  • [iPhone] Switch UIViews

    Hi.
    I just have a pretty basic question actually: How do I switch between views on the iPhone?
    I don't want to use a tab bar controller or navigation controller. Tapping a button on one screen (view) should bring the user to another screen. Possibly I want to have a nice transition animation, like a flip or a sliding animation.
    Right now I'm just adding multiple views to the window and I just view / hide them according to what I want to show. It seems to be ineffective. I would much rather have a stack or something, so that only views that are currently displayed are loaded into memory. Also, I don't want to worry about hiding views that are not shown. Something like switchToView:viewXYZ would be much rather preferred. Is that even possible. Maybe with a view controller? There must be a way, right? I don't thing I'm supposed to just hide / show views.
    Thank you very much!
    Florian

    Interesting.. I have been using the UIView animation for changing views, but had not figured out yet how to push a view right or left.. however, when I try this, it does not work as expected. The push works, but the new view also "fades" in while pushing.. instead of a clean push.. any thoughts?
    Here is the code...
    CATransition* trans = [CATransition animation];
    [trans setType:kCATransitionPush];
    [trans setDuration:0.5];
    [trans setSubtype:kCATransitionFromBottom];
    ... code to change the view...
    CALayer *layer = rootViewController.view.layer;
    [layer addAnimation:trans forKey:@"Transition"];
    also tried :
    [trans setType:kCATransitionMoveIn];
    I have only tried this on the simulator.. I guess I should try it on the device. as I have noticed other animations do not display properly on the simulator (for example, CurlUp does a dissolve... in the sim but works on the device..) I will update when I test it.
    thanks!
    michael golden

Maybe you are looking for