2012-09-30 5 views
1

10 개의 이미지가있는 스크롤 가능한 갤러리를 만들고 있습니다. 이미지 위에서 멈 추면 현재 이미지가 다른 이미지보다 조금 크게 보이기를 바랍니다. 어떻게 뷰를 초점에 맞추고 프레임을 조정합니까? 드래그가 끝나면 scrollViewDidEndDecelerating 함수가 호출됩니다. 해당 이미지 뷰의 프레임에 대한 참조를 얻으려면 어떻게해야합니까?UIScrollview는 현재 이미지를 확대합니다.

답변

1

이미지 목록이 유한하고 너무 커지지 않으면 이미지 참조에 대한 NSArray를 유지합니다. 그런 다음 scrollViewDidEndDecelerating에서 스크롤 오프셋을 사용하여 스크롤이 중지 된 위치를 결정하고 전체보기에 비례하게 배치하면 표시 할 배열의 인덱스 된 이미지를 알 수 있어야합니다. 이 같은

뭔가,

+0

감사합니다. 그러나 어떻게 imageToShow를 뷰에 설정합니까? – user1191140

2

체크 아웃 iCarousel 대신 바퀴를 개혁의 (구문은 OFF가 될 수 있습니다) 당신은 이런 식으로 시도 할 수 있습니다.

CGFloat centerX = CGRectGetMidX(self.view.bounds); 
for(UIImageView imgView * in self.imageViews) 
{ 
    if(CGRectContainsPoint(imgView, centerX)) // If imgView is close to center 
    { 
     imgView.transform = CGAffineTransformMakeScale(1.2f, 1.2f); 
    } 
    else 
    { 
     imgView.transform = CGAffineTransformIdentity; 
    } 
} 

나는 당신이 수평으로 스크롤되는 가정,하지만 당신은 수직으로하고 있다면, 당신은 대신 centerY를 사용해야합니다.

3

https://github.com/nicklockwood/iCarousel 당신이 self.imageViewsUIImageView의 참조를 유지하는 것이의 말을하자 ....

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{ 
    //assumes that "arrayOfImages" is the array of images that you are showing 
    //contentOffset.y assumes your scroll view is scrolling vertically, switch to x if horizontal 
    int indexOfImageToShow = scrollView.contentOffset.y/[arrayOfImages count]; 
    UIImage *imageToShow = [arrayOfImages objectAtIndex:indexOfImageToShow]; 
} 
관련 문제