2012-10-07 80 views
0

當我在Xcode中製作和設置scrollView時,它永遠不會起作用。它不會滾動並顯示我的內容!我編寫了它的後端,但沒有去!我一直在使用這個教程,因爲iOS 4:Devx Scrollview TutorialScrollView在iOS 6中搞亂了

現在,我認爲它是壞的iOS 6由於新的iPhone上的新屏幕尺寸。這裏是後端代碼我一直使用:

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. 
} 
+0

什麼是特別不發生,你期待? – Luke

+0

滾動!抱歉。 – Keaton

+0

好的,但您在滾動視圖中有多少內容?如果它小於剛剛設置的內容大小的高度,則不會滾動。通常,您將內容大小的高度設置爲最後一個對象的y原點加上其高度。 – Luke

回答

0

您設置幀的大小和內容的大小是一樣的。您期望滾動視圖滾動到哪裏?您應該將UIScrollViewframe設置爲您希望視口在屏幕上的位置(可能爲[UIScreen mainScreen].bounds),並將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]; 
+0

下的代碼,並且如果我希望內容變得更高,我是否將scrollview的高度設置爲520? – Keaton

+0

不,如我所說,您將滾動視圖的高度設置爲您希望人們一次看到的區域,並將內容大小設置爲總內容大小。 – Kevin

+0

擰它。擰這一切 – Keaton

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]; 

}