Domanda

I am trying to create a UIScrollView - but it doesnt work. I only see one image in the view - swipe1. The scroll view does scroll forward but its blank and I dont see the other 2 images.

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
È stato utile?

Soluzione

because three images frame are same . you need to set frame like this:

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);

Altri suggerimenti

All of your imageView's are going to have an origin of [0, 0] so they will all overlap.

What you need to do is offset the frame of each image so it appears next to the previous image

%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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top