2012-10-07 5 views
0

Xcode에서 scrollView를 만들고 설정할 때 절대로 작동하지 않습니다. 단순히 스크롤하고 내 콘텐츠를 보여주지 않을 것입니다! 나는 그것의 백엔드를 코딩했지만 아무런 시도도하지 않았다! 나는이 튜토리얼을 iOS 4 이후에 사용 해왔다. Devx Scrollview TutorialiOS 6에서는 ScrollView가 엉망입니다.

이제 새로운 아이폰의 새로운 화면 크기 때문에 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. 

있는 ScrollView의 크기는 폭 : 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입니다.

간단한 예제 프로그램을 작성했습니다. 나는 새로운 "단일보기"프로젝트를 생성하고 단지 주요 VC의 viewDidLoad 방법에 넣고 :

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

}

관련 문제