0
- 的UIView包含一個ImageView的
- 的UIScrollView添加在此的UIView,使滾動(沒有工作)
- 我有一個AlertView到彈出這個UIView的
- 我加入的UIImageView,並作爲的UIScrollView UIView的
我每次運行代碼的子視圖,有沒有SI gn的scrollview的存在。我不知道爲什麼。
下面是代碼:
- (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];
}
工作般的魅力!謝謝! – 2014-10-01 06:16:14
你能告訴我如何在這種情況下啓用縮放嗎?我嘗試: scrollView.delegate = alertView; 再加入這個滾動視圖的委託方法: 但它不工作。 – 2014-10-01 06:59:31
除非您爲警報視圖創建子類,否則您將要將該委託設置爲視圖控制器。然後設置最小和最大縮放比例。最後實現'viewForZoomingInScrollView'方法並返回'demoView'。 – 2014-10-01 14:35:59