2014-02-15 50 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

因爲三幅圖像幀相同。 你需要設置框架是這樣的:

您的ImageView的
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

所有的打算有[0, 0],使他們將所有重疊的起源。

你需要做的是相互抵消圖像的幀所以什麼旁邊會出現以前的圖像

%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 
相關問題