2014-02-15 3 views
0

UIScrollView를 만들려고하는데 작동하지 않습니다. 보기에서 하나의 이미지 만 볼 수 있습니다 (swipe1). 스크롤보기는 앞으로 스크롤하지만 그 빈 칸과 나는 다른 2 개의 이미지를 보지 못합니다.UIScrollView가 작동하지 않고 하나의 이미지 만 표시됩니다.

def create_image_scroll_view_NICE 
    @scroll_view = UIScrollView.alloc.initWithFrame self.view.bounds 
    @scroll_view.delegate = self 
    @scroll_view.scrollsToTop = false 
    self.view.addSubview @scroll_view 

    @scroll_view.pagingEnabled = true 
    @scroll_view.showsHorizontalScrollIndicator = false 
    @scroll_view.contentSize = CGSizeMake(NUMBER_OF_PAGES * self.view.frame.size.width, self.view.frame.size.height) 

    @delivery_image = UIImageView.alloc.initWithImage(UIImage.imageNamed("swipe3")) 
    @scroll_view.addSubview @delivery_image 

    @notification_image = UIImageView.alloc.initWithImage(UIImage.imageNamed("swipe2")) 
    @scroll_view.addSubview @notification_image 

    @box_image = UIImageView.alloc.initWithImage(UIImage.imageNamed("swipe1")) 
    @scroll_view.addSubview @box_image 
    end 

답변

1

3 개의 이미지 프레임이 동일하기 때문에. 이 같은 프레임을 설정해야합니다의가 [0, 0] 그래서 그들은 모든 중복의 기원을해야 할 것 귀하의 이미지 뷰의

delivery_image.frame = CGRectMake(0,0,width,height); 
notification_image.frame = CGRectMake(self.view.frame.size.width,0,width,height); 
box_image.frame = CGRectMake(self.view.frame.size.width*2,0,width,height); 
1

모든.

는 이전 이미지

%w(swipe3 swipe2 swipe1).each_with_index do |image_name, index| 
    delivery_image = UIImageView.alloc.initWithImage(UIImage.imageNamed(image_name)) 

    x_offset = CGRectGetWidth(self.view.frame) * index 
    delivery_image.frame = [[ x_offset, 0], delivery_image.frame.size ] 

    @scroll_view.addSubview delivery_image 
end 
옆에 나타나도록 각 이미지의 프레임을 상쇄해야 할 일은
관련 문제