2012-07-03 2 views
1

뷰의 프레임이 자동으로 변경되는 이유는 무엇입니까?로드 뷰에서 뷰를 생성하고 프레임을 설정하지만 프레임 자동 변경

- (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)); 
} 

내 데모 출력 :

이 코드를 참조 SV 프레임 = {{-10, 0}, {340, 480}}

보기 프레임 = {{0, 0}, {320, 480}}

이 같아야 뷰 프레임 = {{-10, 0}, {340, 480}}

그러나 PhotoScroller 데모 (2,010 WWDC 104)에

, 그것이 올바른지 . 너무 이상해.

답변

2

변경이 방법 방법 모두 :

- (void)loadView{ 
    UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectZero]; 
    self.view = sv; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    self.view.frame = CGRectMake(-10,0,340,480); 
} 

편집 : 기하 적어도 viewWillAppear: 이상에서 UIViewController의 이벤트 라이프 사이클에 설정해야합니다. 자동 크기 조정 마스크는 또한 형상을 변경할 수 있습니다.

-1

이 시도 :

- (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; 
} 
1
- (void)loadView 
{  
    UISCrollView *scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    self.view = scrollView; 
} 
관련 문제