0

当我在 Xcode 中制作和设置滚动视图时,它永远不会工作。它根本不会滚动并显示我的内容!我已经编码了它的后端,但不行!从 iOS 4 开始我就一直在使用这个教程:Devx Scrollview Tutorial

现在,我认为由于新 iPhone 上的新屏幕尺寸,它在 iOS 6 中被打破了。这是我一直在使用的后端代码:

    scrollView.frame = CGRectMake(0, 0, 320, 520);

//---set the content size of the scroll view---
[scrollView setContentSize:CGSizeMake(320, 520)];
// Do any additional setup after loading the view.

Xcode 中的滚动视图大小为宽度:320,高度:520。

我究竟做错了什么?这可能是一些愚蠢的事情。

更新:

 - (void)viewDidLoad
{
    [super viewDidLoad];
      [self.overlay removeFromSuperview];
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

    [nc addObserver:self selector:@selector(keyboardWillShow:) name:
     UIKeyboardWillShowNotification object:nil];

    [nc addObserver:self selector:@selector(keyboardWillHide:) name:
     UIKeyboardWillHideNotification object:nil];

    tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                            action:@selector(didTapAnywhere:)];
    [self customizeAppearance];
     self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"stone.png"]];

    [scrollView setScrollEnabled:YES];
    scrollView.frame = ([UIScreen mainScreen].bounds);

    //---set the content size of the scroll view---
    [scrollView setContentSize:CGSizeMake(320, 800)];


    // Do any additional setup after loading the view.
}
4

2 回答 2

0

您将框架大小和内容大小设置为相同。您希望滚动视图滚动到哪里?您应该将UIScrollView's设置frame为您希望视口在屏幕上的位置(可能[UIScreen mainScreen].bounds),并将's 设置为contentSize您希望滚动到达的总区域,听起来您希望它是 320x520。

我写了一个简单的示例程序。我创建了一个新的“单一视图”项目并将其放入viewDidLoad主 VC 的方法中:

UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 20, 280, 424)];
UILabel *top = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 280, 50)];
top.text = @"TOP";
top.textColor = [UIColor greenColor];
top.backgroundColor = [UIColor blackColor];
top.textAlignment = UITextAlignmentCenter;
[sv addSubview:top];

UILabel *bottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 500, 280, 50)];
bottom.text = @"BOTTOM";
bottom.textColor = [UIColor greenColor];
bottom.textAlignment = UITextAlignmentCenter;
bottom.backgroundColor = [UIColor blackColor];
[sv addSubview:bottom];

sv.backgroundColor = [UIColor orangeColor];
sv.contentSize = CGSizeMake(280, 550);

[super.view addSubview:sv];
于 2012-10-07T14:36:13.220 回答
0
-(void)screenWasSwiped {

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[scrollpage setScrollEnabled:YES];

[scrollpage setContentSize:CGSizeMake(320, 1300)];

NSLog(@"you swiped the screen UP");

}else {
    [scrollpage setScrollEnabled:YES];

    [scrollpage setContentSize:CGSizeMake(320, 950)];

}

}

-(无效)viewDidLoad {

UISwipeGestureRecognizer *swipeUP = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(screenWasSwiped)];
swipeUP.numberOfTouchesRequired = 1;
swipeUP.direction=UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUP];

}

于 2012-10-08T03:06:20.290 回答