Reputation: 26223
I am sure I have come across this before but I can't remember what was causing it. I have positioned a UIImageView (bar_001) using a storyboard and I want to change its position programatically from within the viewController. My problem is that when accessed from viewDidLoad the UIImageViews size and origin are all just set to zero, what am I missing?
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, weak) IBOutlet UIImageView *bar_001;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self animateBars_V1];
}
- (void)animateBars_V1 {
CGRect barRect = [[self bar_001] frame];
NSLog(@"HEIGHT: %f", barRect.size.height);
NSLog(@"WIDTH : %f", barRect.size.width);
}
@end
CONSOLE:
2012-12-11 12:53:27.777 TESTBED[4279:907] HEIGHT: 0.000000
2012-12-11 12:53:27.785 TESTBED[4279:907] WIDTH : 0.000000
STORYBOARD:
Upvotes: 1
Views: 1021
Reputation: 1296
I have at times seen similar problem as well. I would try calling the animateBars_V1() method in viewDidAppear instead of viewDidLoad. By the time, viewDidLoad is called the view is loaded in the memory but may not have been drawn. I would have to look somethings up before I can give a definite reason for why it behaves like this.
Upvotes: 4