嗨,我有一個大的圖像和它在一個特定的位置的小圖像... 我將它們全部添加到ScrollView下,但它不能正常工作? 我要放大,一起各在其位我怎樣才能使用UIScrollView重疊圖像iphone
這裏是我的代碼:
myScrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
myScrollView.maximumZoomScale = 3.0;
myScrollView.minimumZoomScale = 1.0;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
[myScrollView addSubview:imageView];
感謝
嗨,麥克沃思;我做到了,但如果我沒有最大化圖像,我無法在任何地方移動滾動視圖,但如果我放大它,我可以看到其餘的部分..我不知道爲什麼我試圖改變它,但它工作。你能看看下面的代碼嗎?
- (void)viewDidLoad{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"ucd.png"];
//creating a view for UCD image
ucdView = [[UIImageView alloc] initWithImage:image];
//setting the frame for the ucdView as the same size of ucd image
[ucdView setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
//for the red pin to display in specific loc
UIImageView *Health = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redPin.png"]];
[Health setCenter:CGPointMake(310,135)];
//adding helathView to ucdview
[ucdView addSubview:Health];
//everything for scroll view
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ucdView.frame.size.width, ucdView.frame.size.height)];
[scrollView setMinimumZoomScale:1.0];
[scrollView setMaximumZoomScale:3.0];
scrollView.clipsToBounds = YES;
[scrollView setContentSize:CGSizeMake(image.size.width, image.size.height)];
[scrollView setDelegate:self];
[scrollView addSubview:ucdView];//adding ucd view to scroll view
[self.view addSubview:scrollView]; // adding scrollview to self.view main view
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {//apply zooming for scrollview
return scrollView;
}
HI馬克沃斯可以請你檢查我張貼上面的答案,,, – Dalal
請參閱我的答案的編輯版本。另外,恐怕我不能完全解析「我做了它,但如果我沒有最大化圖像,我無法在任何地方移動滾動視圖,但是如果我放大它,我可以看到其餘的..我不知道我爲什麼試圖改變它,但它工作。「也許再拍一下? – mackworth
嗨麥克,感謝您的答覆百萬,,,我修復了代碼,你的幫助我很多.... – Dalal