2009-06-16 4 views
1

기본보기가 480 x 510 인 iPhone 앱이 있습니다. 세로에서 가로로 갈 때 좌표계가 어떻게 변경되는지 혼란 스럽습니다.UIScrollView 시작 지점

처음에는 480x480 콘텐츠 영역이 있었으며 옆에 버튼을 추가하여 메뉴를 표시하려고했습니다. 그러나 필자가 앱의 왼쪽면의 길이를 줄이기 위해 찾을 수있는 유일한 방법은 전체 앱의 방향을 가로 방향으로 변경하는 것이 었습니다.

Landscape에서 방향을 지정하면 스크롤보기가 왼쪽 아래에서 시작하여 원래의 방향 포인트 (세로 모드에서 시작했을 때)에서 시작되도록합니다. 그러나 scrollview의 원래 시작점을 변경하는 방법을 알 수는 없습니다. contentOffset 시도했지만 작동하지 않는 것.

이 작업을 수행하는 또 다른 방법은 버튼에 제목이 표시되는 것을 잊어 버리고 세로 방향 텍스트가있는 버튼의 그래픽을 만드는 것입니다.

if (self = [super initWithCoder:coder]) { 
    // Size of the scrollview 
    self.contentSize = CGSizeMake(480, 510); 
    [self setContentOffset:CGPointMake (0, -160)]; 
    self.showsHorizontalScrollIndicator = YES; 
    self.showsVerticalScrollIndicator = YES; 
    self.alwaysBounceVertical = NO; 
    self.alwaysBounceHorizontal = NO; 
    self.bounces = YES; 
    self.userInteractionEnabled = YES; 
    self.musicGridView = [[[MusicGridView alloc] initWithCoder:coder] autorelease]; 
    // Rectangle where I put the music grid (origin is left aligned, and down 160 pixels to account for landscape view) 
    self.musicGridView.frame = CGRectMake(0, 160, 480, 480); 
    [self addSubview: musicGridView]; 

    self.menuButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    self.menuButton.frame = CGRectMake(0, 480, 480, 32); 
    [menuButton setTitle: @"Tap to get Menu" forState: UIControlStateNormal]; 
    [menuButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 
    [menuButton addTarget:self action:@selector(showMenu) forControlEvents:UIControlEventTouchUpInside]; 

    [self addSubview: menuButton]; 

답변

0

Andrey Tarantsov는 일반적인 문제에 대한 다양한 해결 방법에 대한 코드를 포함하여 UIScrollView 클래스의 여러 단점의 awesome rundown 수행하고있다. 보람을 느낄 수도 있습니다.

1

단순히

//it goes in particular pont of view 

[scrollview setContentOffset:CGPointMake(x,y) animated:YES]; 

//if x=0 in loop, increase y value scrollview move only vertical direction 
[scrollview setContentOffset:CGPointMake(0,y) animated:YES]; 

//if y=0 in loop, increase x values scrollview move only horizontal direction 
[scrollview setContentOffset:CGPointMake(x,0) animated:YES]; 
에서, Y를 점 X를 설정