0

XcodeでscrollViewを作成してセットアップすると、機能しません。スクロールしてコンテンツが表示されないだけです。私はそれのバックエンドをコーディングしましたが、行きません!私はiOS4からこのチュートリアルを使用しています:DevxScrollviewチュートリアル

さて、新しいiPhoneの新しい画面サイズのために、iOS6では壊れていると思います。これが私が使用しているバックエンドコードです:

    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'を設定する必要があります。また、スクロールが到達する合計領域になるように設定する必要があります。これは、320x520にする必要があるように聞こえます。frame[UIScreen mainScreen].boundscontentSize

簡単なサンプルプログラムを作成しました。新しい「シングルビュー」プロジェクトを作成し、これを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)];

}

}

-(void)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 に答える