2011-04-20 4 views
3

새로운 뷰를 표시하기 위해 스 와이프 할 수있는 UIScrollView가 있습니다. 프로그램 적으로보기를 스크롤하려는 버튼이 있습니다. 한 번 클릭하면 다음보기로 스크롤됩니다. 어떻게 구현할 수 있습니까? 여기 프로그래밍 방식으로 UIScrollView를 스크롤하는 방법은 무엇입니까?

스크롤 뷰에 첨가 myView 가정하고있는 ScrollView 코드

- (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView 
{ 
    NSUInteger offset = aScrollView.contentOffset.x; 
    NSUInteger width = aScrollView.contentSize.width; 
    int anIndex = (offset == 0) ? 0 : (int)(width/(width - offset)); 
    selectedDeal = [deals objectAtIndex:(anIndex > [deals count]- 1 ? [deals count]- 1 : anIndex)]; 
} 
+0

이 코드와 질문의 관계는 무엇입니까? – taskinoor

답변

3
[myScrollView scrollRectToVisible:myView.frame animated:TRUE]; 

이 너무 myView 가시가되도록 스크롤을하고 이미 볼 수 없다. 현재 보이는 뷰를 추적하고 단추 처리기에서 위의 방법에 대한 매개 변수로 다음 뷰의 프레임을 전달해야합니다.

1
[myScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0)animated:YES]; 

[myScrollView scrollRectToVisible:self.view.frame animated:YES]; 
+0

완벽하게 작동합니다. 감사 –

관련 문제