Reputation: 1500
Why the frame of the view auto changed?
see this codes:
- (void)loadView{
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(-10,0,340,480)];
self.view = sv;
NSLog(@"sv frame = %@", NSStringFromCGRect(self.view))
}
- (void)viewWillAppear{
NSLog(@"view frame = %@", NSStringFromCGRect(self.view));
}
In my demo Output : sv frame = {{-10, 0}, {340, 480}}
view frame = {{0, 0}, {320, 480}}
It should be: view frame = {{-10, 0}, {340, 480}}
But in PhotoScroller demo (2010 WWDC 104), it's correct. It's so strange.
Upvotes: 1
Views: 707
Reputation: 11174
- (void)loadView
{
UISCrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = scrollView;
}
Upvotes: 1
Reputation: 1337
try this:
- (void)loadView{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(-10,0,340,480)];
[view addSubview:sv];
sv.autoresizingMak=UIViewAutoresizingMaskFlexibleWidth|UIViewAutoresizingMaskFlexibleHeight;
self.view = view;
}
Upvotes: -1
Reputation: 15213
Change both of the methods this way:
- (void)loadView{
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectZero];
self.view = sv;
}
- (void)viewWillAppear:(BOOL)animated {
self.view.frame = CGRectMake(-10,0,340,480);
}
EDIT: Geometry MUST be set in at least viewWillAppear:
and later on UIViewController
's event lifecycle. Autoresizing masks also can change the geometry.
Upvotes: 2