UIImageView Is Moving View to 0,0

Today I had weird problem while creating one iPhone application.

I have created one UIView and added one UIImageView to it and loaded it with Default.png image, but when starting the program whole view is moved up for 20px, it’s y reference is starting from 0 instead from 20, so here is how to fix it easily.

In application didFinishLaunching delegate add following code before [window makeKeyAndVisible]; and after [window addSubview:yourView];

1
2
3
4
5
6
7
8
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  [window addSubview:yourView];
  [yourView setFrame:CGRectMake(0, 20, 320, 460)]; // so you are creating frame which x starts on 0, y starts on 20px and with dimensions 320px x 460px
  [window makeKeyAndVisible];

  return YES;
}
iOS