我有:
每次运行代码时,都没有滚动视图存在的迹象。我不知道为什么。
以下是代码:
- (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];
}
答案 0 :(得分:0)
现在您正在将scrollview
添加到demoView
。它应该是另一种方式。
//add scrollview
[scrollview addSubview:demoView];
如果您希望scrollview
成为警报视图的contentView,您还需要将其设置为警报视图,而不是demoView
。
// Add some custom content to the alert view
[alertView setContainerView:scrollview];
您的最终视图层次结构应如下所示:
| AlertView
| --- ScrollView
| ------- DemoView
| ----------- ImageView