2012-08-03 4 views
3

superview와 동일한 너비 인 UIScrollView가 있습니다. 그것은 매우 넓은 contentSize를 가지며 가로로 스크롤합니다.uiscrollviewdelegate에서 targetContentOffset을 음수 값으로 설정할 수 있습니까?

위임 메서드 scrollViewWillEndDragging : withVelocity : targetContentOffset :을 사용하여 targetContentOffset-> x를 음수 값으로 설정하려고합니다 (즉, 콘텐츠 영역의 왼쪽 가장자리를 화면 가운데로 이동). 값이 작동하는 것 같다 설정

은 (NSLog 전후의 변화를 보여줍니다)하지만있는 ScrollView 수정 된 targetContentOffset을 무시하는 것 같다 그냥이 할 수 있으면 누구나 알고 있나요 0

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 
{ 
    NSLog(@"target: %@", NSStringFromCGPoint(*targetContentOffset)); 
    if (targetContentOffset->x <= 0.0) 
    { 
     targetContentOffset->x = -300; 
    } 

    NSLog(@"target: %@", NSStringFromCGPoint(*targetContentOffset)); 
} 

에서 스크롤 끝단 이 방법을 사용하거나 다른 방법으로해야합니까?

+0

또 다른 방법 수평 스크롤에 사용을 향상시킬 수 있습니다에 "봄"있는 ScrollView를 알 수있는 방법이에 : 여기

는 스위프트의 예입니다 다른 곳? ContentInset 시도 했습니까? –

+0

@Killian : 문제의 해결책을 찾았습니까? – matm

답변

1

나는 contentInset 속성으로 조작하여 유사한 문제를 해결할 수있었습니다.

다시
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { 
    // Determine threshold for dragging to freeze content at the certain position 
    if scrollView.contentOffset.y < -50 { 
     // Save current drag offset to make smooth animation lately 
     var offsetY = scrollView.contentOffset.y 
     // Set top inset for the content to freeze at 
     scrollView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0) 
     // Set total content offset to preserved value after dragging 
     scrollView.setContentOffset(CGPoint(x: 0, y: offsetY), animated: false) 
     // Make any async function you needed to 
     yourAsyncMethod(complete: {() -> Void in 
      // Set final top inset to zero 
      self.tripsTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0) 
      // Set total content offset to initial position 
      self.tripsTableView.setContentOffset(CGPoint(x: 0, y: -50), animated: false) 
      // Animate content offset to zero 
      self.tripsTableView.setContentOffset(CGPoint(x: 0, y: 0), animated: true) 
     }) 
    } 
} 

당신은 질문은 물어

관련 문제