0
votes

I have:

  1. UIView to contain an ImageView
  2. UIScrollView add in this UIView to enable Scroll (Which did not work)
  3. I have an AlertView to pop up this UIView
  4. I added UIImageView, and UIScrollView as subview of UIView

Every time I run the code, there's no sign of the existence of scrollview. I don't know why.

Here is the code:

- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {



    //create image

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 500, 500)];



    //create a scrollview to contain the uiview above

    UIScrollView* scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,480)];

    scrollview.showsVerticalScrollIndicator=YES;

    scrollview.scrollEnabled=YES;

    scrollview.userInteractionEnabled=YES;

    [scrollview setDelegate:self];

    [scrollview setBouncesZoom:YES];



    scrollview.contentSize = CGSizeMake(500,500);

    //create a view to show picture

    UIView *demoView = [[UIView alloc] init];

    if(gestureRecognizer.view == _firstImageView){

        UIImage *image = [UIImage imageNamed:_photoDetailModel[1]];

        [imageView setImage:image];



        CGSize imageSize = imageView.image.size;

        [demoView setFrame: CGRectMake(0, 0, 290, 200)];

//        [demoView setFrame: CGRectMake(0, 0,imageSize.width, imageSize.height)];

    }else{

        UIImage *image = [UIImage imageNamed:_photoDetailModel[2]];

        [imageView setImage:image];



        CGSize imageSize = imageView.image.size;

        [demoView setFrame: CGRectMake(0, 0, 290, 200)];

    }

    //add imageview

    [demoView addSubview:imageView];



    //add scollview

    [demoView addSubview:scrollview];



    //create a pop up view to contain the above uiview

    CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];



    // Add some custom content to the alert view

    [alertView setContainerView: demoView];



    // Modify the parameters

    [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Close", nil]];



    // You may use a Block, rather than a delegate.

//    [alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) {

//        NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, (int)[alertView tag]);

//        [alertView close];

//    }];



    [alertView setUseMotionEffects:true];



    // And launch the dialog

    [alertView show];

}
1

1 Answers

0
votes

Right now you're adding the scrollview to the demoView. It should be the other way around.

//add scrollview
[scrollview addSubview:demoView];

If you want scrollview to be the contentView of the alert view, you also want to set that as the alert view, not demoView.

// Add some custom content to the alert view
[alertView setContainerView:scrollview];

Your final view hierarchy should be as follows:

| AlertView
| --- ScrollView
| ------- DemoView
| ----------- ImageView