0

I have a UIScrollView which contains full width images. I want a UIView on top of the UIScrollView at every point of time. Initially the output is correct, I am getting the UIView over the UIScrollView. But when I scroll right, the UIView is moving along with the first image to the left. How can I keep the UIView always on top ? Do I need to implement any other methodology ?

-(void)setSalonImagesScrollView{

int x = 0;

for (int i = 0; i < [self.imageList count]; i++) {

    CGFloat xOrigin = i * self.view.frame.size.width;
    UIImageView *salImg =[[UIImageView alloc] initWithFrame:CGRectMake(xOrigin,0,320,194)];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageList[i]]];

    salImg.image = [UIImage imageWithData:imageData];
    salImg.tag = i;
    [self.salonImgCarousel addSubview:salImg];
    [self.salonImgCarousel insertSubview:self.navSubView belowSubview:self.navSubView];

    x += salImg.frame.size.width;
}

self.salonImgCarousel.contentSize = CGSizeMake(x, self.salonImgCarousel.frame.size.height);

[_salonImgCarousel setShowsHorizontalScrollIndicator:NO];
[_salonImgCarousel setDelegate:self];}
Himanshu padia
  • 7,428
  • 1
  • 47
  • 45

3 Answers3

0

The problem here is that, you are adding your imageView to the ScrollView. Everything you'll add to the ScrollView will be scrolled. You have to add your imageView to the View instead of ScrollView.

[self.view addSubview:salImg];

Kunal Kumar
  • 1,722
  • 1
  • 17
  • 32
0

Try this

-(void)setSalonImagesScrollView{
int x = 0;

for (int i = 0; i < [self.imageList count]; i++) {

CGFloat xOrigin = i * self.view.frame.size.width;
UIImageView *salImg =[[UIImageView alloc] initWithFrame:CGRectMake(xOrigin,0,320,194)];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageList[i]]];

salImg.image = [UIImage imageWithData:imageData];
salImg.tag = i;
[self.view addSubview:salImg];
[self.salonImgCarousel insertSubview:self.navSubView belowSubview:self.navSubView];

x += salImg.frame.size.width;
}

self.salonImgCarousel.contentSize = CGSizeMake(x, self.salonImgCarousel.frame.size.height);

[_salonImgCarousel setShowsHorizontalScrollIndicator:NO];
[_salonImgCarousel setDelegate:self];}

and post your difficulty

Kind Regards

Koushik

Koushik
  • 1,220
  • 15
  • 19
0

If you want UIView every time on top of your screen then best way is add UIView on UIWindow.

Ex.

[window addSubView:myView];

Also look at How can access window in my view controller

Community
  • 1
  • 1
iPatel
  • 46,010
  • 16
  • 115
  • 137