2012-02-21 4 views
1

애플은 아이폰 캘린더 날짜 뷰 전환을 어떻게합니까? 낮보기에서 손가락을 스 와이프하면 회전 목마처럼 보입니다. 화면의 절반 정도가 화면 위쪽에 있으면 날짜가 바뀝니다.iOS : 캘린더 데이 전이보기

본인이 직접 요일보기를 다시 만들었지 만 일 사이의 전환을 수행하는 방법을 알아야합니다.

답변

1

내가 추측해야한다면? this method처럼 UIScrollView에서 3 개의 창을 사용합니다.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    documentTitles = [[NSMutableArray alloc] init]; 

    // create our array of documents 
    for (int i = 0; i < 10; i++) { 
    [documentTitles addObject:[NSString stringWithFormat:@"Document %i",i+1]]; 
    } 

    // create placeholders for each of our documents 
    pageOneDoc = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
    pageTwoDoc = [[UILabel alloc] initWithFrame:CGRectMake(320, 0, 320, 44)]; 
    pageThreeDoc = [[UILabel alloc] initWithFrame:CGRectMake(640, 0, 320, 44)]; 

    pageOneDoc.textAlignment = UITextAlignmentCenter; 
    pageTwoDoc.textAlignment = UITextAlignmentCenter; 
    pageThreeDoc.textAlignment = UITextAlignmentCenter; 

    // load all three pages into our scroll view 
    [self loadPageWithId:9 onPage:0]; 
    [self loadPageWithId:0 onPage:1]; 
    [self loadPageWithId:1 onPage:2]; 

    [scrollView addSubview:pageOneDoc]; 
    [scrollView addSubview:pageTwoDoc]; 
    [scrollView addSubview:pageThreeDoc]; 

    // adjust content size for three pages of data and reposition to center page 
    scrollView.contentSize = CGSizeMake(960, 416); 
    [scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO]; 
} 

- (void)loadPageWithId:(int)index onPage:(int)page 
{ 
    // load data for page 
    switch (page) { 
    case 0: 
     pageOneDoc.text = [documentTitles objectAtIndex:index]; 
     break; 
    case 1: 
     pageTwoDoc.text = [documentTitles objectAtIndex:index]; 
     break; 
    case 2: 
     pageThreeDoc.text = [documentTitles objectAtIndex:index]; 
     break; 
    } 
} 

- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender 
{ 
    // All data for the documents are stored in an array (documentTitles). 
    // We keep track of the index that we are scrolling to so that we 
    // know what data to load for each page. 
    if(scrollView.contentOffset.x > scrollView.frame.size.width) 
    { 
    // We are moving forward. Load the current doc data on the first page. 
    [self loadPageWithId:currIndex onPage:0]; 

    // Add one to the currentIndex or reset to 0 if we have reached the end. 
    currIndex = (currIndex $gt;= [documentTitles count]-1) ? 0 : currIndex + 1; 
    [self loadPageWithId:currIndex onPage:1]; 

    // Load content on the last page. This is either from the next item in the array 
    // or the first if we have reached the end. 
    nextIndex = (currIndex $gt;= [documentTitles count]-1) ? 0 : currIndex + 1; 

    [self loadPageWithId:nextIndex onPage:2]; 
    } 
    if(scrollView.contentOffset.x $lt; scrollView.frame.size.width) { 
    // We are moving backward. Load the current doc data on the last page. 
    [self loadPageWithId:currIndex onPage:2]; 

    // Subtract one from the currentIndex or go to the end if we have reached the beginning. 
    currIndex = (currIndex == 0) ? [documentTitles count]-1 : currIndex - 1; 
    [self loadPageWithId:currIndex onPage:1]; 

    // Load content on the first page. This is either from the prev item in the array 
    // or the last if we have reached the beginning. 
    prevIndex = (currIndex == 0) ? [documentTitles count]-1 : currIndex - 1; 

    [self loadPageWithId:prevIndex onPage:0]; 
    }  

    // Reset offset back to middle page 
    [scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO]; 
} 
+0

한 번에 3 개만로드하는 것 같습니다. 왼쪽, 가운데 및 오른쪽 페이지? 정말로 그것 scrollview 생각하십니까? – Bot

+0

UIScrollView는 매우 강력하지만 많은 사람들이 오해하고 있습니다. – slf

0

이렇게하려면 스크롤보기가 필요하지 않습니다. 3 개의 하위 뷰가 나란히 배치 된 뷰를 만들고 팬 제스처 인식기를 추가하면됩니다.

사용자가 오른쪽보기로 이동 한 경우 가장 왼쪽보기를 밖으로 내밀고 오른쪽에보기를 추가하고 현재 오른쪽에서 가운데보기를 봅니다. 왼쪽 뷰에서도 비슷한 작업을 수행해야합니다.

관련 문제