1

我有一个主视图为 480 x 510 的 iPhone 应用程序。当我从纵向变为横向时,我对坐标系如何变化感到有些困惑。

最初,我有一个 480x480 的内容区域,并且想在侧面添加一个按钮来调出菜单。但是,我能找到的让文字沿着应用左侧的长度运行的唯一方法是将整个应用的方向更改为横向右侧。

现在,随着横向的方向,滚动视图从左上角开始,当我真的希望它从原始方向点开始(从它处于纵向模式时),这将是左下角。但我不知道如何改变滚动视图的原始起点。我尝试了 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];
4

2 回答 2

1

只需将点 x,y 设置为

//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];
于 2012-08-31T10:18:47.610 回答
0

Andrey Tarantsov对课程的各种怪癖进行了精彩UIScrollView的总结,包括针对常见问题的各种变通方法的代码。可能值得一看。

于 2009-06-17T01:20:34.943 回答