0

请原谅糟糕的代码 atm,只是想在让它看起来不错之前让它工作。所以我试图让 UIScrollView 工作。如果我删除所有滚动视图的内容,我会得到一个布局精美的页面,其中包含 64 个按钮,页面两侧各有 32 个按钮。这些按钮几乎是微型的;所以我想实现缩放以便能够点击它们。

Zoom 目前有意想不到的结果。当页面开始时,它是空白的。缩放意外地在页面的右侧显示了图表的一些左侧,当我尝试向它滚动时它会反弹。但是当我放大更多时,它允许我更多地向按钮中间滚动。当我滚动/缩放时,总是给我带来困难/窃听。所以显然无法使用。

我的viewDidLoad:

[super viewDidLoad];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.minimumZoomScale = 0.5;
scroll.maximumZoomScale = 3.0;
scroll.delegate = self;
    CGFloat yOrigin = self.view.frame.size.width;
    UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];

// iterate over values in the staff array
int heightBetweenBrackets = 0;
int widthBetweenBrackets = 0;
int heightFromTop = 45;

for(int i = 0; i < 64; i++)
{
    if(i == 32)
    {
        heightBetweenBrackets = 0;
    }
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(
                                0 + i/32*438,
                                heightFromTop + i%32*3+ heightBetweenBrackets, 
                                35, 6);
    [myButton setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
    myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
    [myButton.titleLabel setFont:[UIFont fontWithName:@"Arial" size:7]];
    myButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    //   [myButton addTarget:self action:@selector(chooseWinner:) forControlEvents:UIControlEventTouchUpInside];
    [awesomeView addSubview:myButton];
    heightBetweenBrackets += (i%2  -1 * -1) * 3;
}

[scroll addSubview:awesomeView];
scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:scroll];

和:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.view;
}

如果错误很愚蠢,我深表歉意我只是在学习 IOS =] 感谢您的时间

编辑:想通了。

对于未来的任何人:我移植了一个分页滚动器,但没有意识到我保留了 CGFloat yOrigin = self.view.frame.size.width; - 这当然是直接在任何可见空间的右侧开始视图。因此,我能够以一种错误的方式放大并看到它的左侧,尽管它开始时是空白的。只需将其更改为 0 即可解决我的问题。

4

1 回答 1

0

对于未来的任何人:我移植了一个分页滚动器,但没有意识到我保留了 CGFloat yOrigin = self.view.frame.size.width; - 这当然是直接在任何可见空间的右侧开始视图。因此,我能够以一种错误的方式放大并看到它的左侧,尽管它开始时是空白的。只需将其更改为 0 即可解决我的问题。

于 2012-05-03T07:24:15.253 回答