2011-06-15 23 views

답변

0

스크롤 오프셋 컨텐츠를 설정하여 달성을 도와주세요.

(예 -viewDidLoad에서) 같은 것을 만들어보기 컨트롤러를 상상해

// Load image. 
UIImage *image = [UIImage imageNamed:@"image.png"]; 

// Create image view to hold the image. 
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, [image size].width, [image size].height)]; 

[imageView setImage:image]; 

// Create a scroll view that is the size of the view. 
scrollView = [[UIScrollView alloc] initWithFrame:[[self view] bounds]]; 

// Important: If the content size is less than the scroll view frame, then it will not scroll. 
[scrollView setContentSize:[image size]]; 

// Add to view hierarchy. 
[scrollView addSubview:imageView]; 
[[self view] addSubview:scrollView]; 

이 스크롤하려면 바로이 작업을 수행 :

[scrollView setContentOffset:CGPointMake(0, 100) animated:YES]; 

연속 될 수있는 스크롤을 사용하려면, 콘텐츠 오프셋을 업데이트하는 타이머를 설정해야합니다.

4
- (void) scrollView 
{ 
    CGFloat currentOffset = scrollImage.contentOffset.x; 

    CGFloat newOffset; 

    if(currentOffset == 3840) 
    { 
     currentOffset = -320.0; 

     [scrollImage setContentOffset:CGPointMake(newOffset,0.0) animated:NO]; 
    } 

    newOffset = currentOffset + 320; 

     [UIScrollView beginAnimations:nil context:NULL]; 
     [UIScrollView setAnimationDuration:2.1]; 
     [scrollImage setContentOffset:CGPointMake(newOffset,0.0)]; 
     [UIScrollView commitAnimations]; 
} 
+0

답변을 게시 해 주셔서 감사합니다! 코드 스 니펫이 질문에 대답 할 수는 있지만 설명과 같이 추가 정보를 추가하는 것이 좋습니다. – j0k

관련 문제