我使用的UIScrollView用於捏縮放圖像我使用的代碼是這樣的的UIScrollView保持按鈕固定位置
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame]; //Full Screen
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:fullScreenRect];
scroll.backgroundColor = [UIColor clearColor];
scroll.delegate = self;
scroll.contentSize = _imageView.frame.size;
[scroll addSubview:_imageView];
scroll.minimumZoomScale = 1.0;
scroll.maximumZoomScale = 5.0;
[scroll setZoomScale:scroll.minimumZoomScale];
self.view = scroll;
[scroll addSubview:_screenShotButton];
[scroll addSubview:_resolutionButton];
-(void)aligementTheControlBasedOnOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
bool ipad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
if (ipad) {
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
_imageView.frame = CGRectMake(142, 114, 740, 555);
if ([self.resoultion isEqualToString:@"Default"]) {
_imageView.frame = CGRectMake(142, 114, 740, 555);
}
else if([self.resoultion isEqualToString:@"4:3"])
_imageView.frame = CGRectMake(142, 114, 740, 555);
else if([self.resoultion isEqualToString:@"16:9"])
_imageView.frame = CGRectMake(142, 114, 740, 416);
self.screenShotButton.frame = CGRectMake(794, 667, 55, 55);
self.resolutionButton.frame = CGRectMake(857, 667, 55, 55);
}
else
{
_imageView.frame = CGRectMake(64, 238, 640, 480);
if ([self.resoultion isEqualToString:@"Default"]) {
_imageView.frame = CGRectMake(64, 238, 640, 480);
}
else if([self.resoultion isEqualToString:@"4:3"])
_imageView.frame = CGRectMake(64, 238, 640, 480);
else if([self.resoultion isEqualToString:@"16:9"])
_imageView.frame = CGRectMake(64, 238, 640, 360);
self.screenShotButton.frame = CGRectMake(578, 749, 55, 55);
self.resolutionButton.frame = CGRectMake(649, 749, 55, 55);
}
}
}
基於分辨率用戶
已選擇我定位的按鈕。
一切工作正常。我正面臨的問題是_screenShotButton和_resolutionButton在我縮放圖像時也在移動。相反,我想保持靜態按鈕在屏幕的右下角。
任何人都可以幫助我。
我也注意到您更換了'你'scroll' self.view'。考慮*將'self.view'作爲'self.view'的子視圖添加*滾動,以便您可以使用超級視圖添加按鈕。 – SwiftArchitect