So i want to add subview (UIImageView) to my main view with the following code:
NSString *fileLocation = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"background_main.png"];
_aImage = [[UIImage alloc] initWithContentsOfFile:fileLocation];
_aImageView = [[UIImageView alloc] initWithImage:_aImage];
_aImageView.frame = CGRectMake(-200, 0, _aImage.size.width, _aImage.size.height);
[self.view addSubview:_aImageView];
as you can see - i'm adding UIImageView to position (-200;0);
But it shows up at default position : (0;0).
My view hierarchy:
- self.view -main view where i'm adding subview(UIImageView);
- _aImageView - UIImageView that i'm adding.
Results:
NSLog(@"image is %@",_aImageView); //result (-200 0; 420 568)
CGPoint test = [_aImageView convertPoint:_aImageView.frame.origin toView:self.view];
NSLog(@"convert %f %f",test.x,test.y); //result (-400.000000; 0.000000)
I know that position is still (0;0) because i can see it when i testing my app. Later when i'm changing position of _aImageView to (-50;0) it's shows black screen. I know i'm missing something very important but i can't figure out why it shows up at (0;0) position.
Links to similar questions that i have checked: