2 개의 장치에서 잘 작동하는 loadView 메서드에 조건부 부동 소수점이 있습니다. 그러나, 나는 방향을 바꾸기 위해 이러한 변화를 만드는 방법을 찾기 위해 최악의 시간을 보냈습니다.iOS의 방향 변경 높이
내 Prefix.pch이 있습니다
#define dDeviceOrientation [[UIDevice currentDevice] orientation]
#define isPortrait UIDeviceOrientationIsPortrait(dDeviceOrientation)
#define isLandscape UIDeviceOrientationIsLandscape(dDeviceOrientation)
#define isFaceUp dDeviceOrientation == UIDeviceOrientationFaceUp ? YES : NO
#define isFaceDown dDeviceOrientation == UIDeviceOrientationFaceDown ? YES : NO
내에는 loadView 방법 내가 처음 작품을 알고 싶어하기 때문에 (세로이가 ... :
이CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = CGRectGetHeight(screenBounds);
float Y;
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)){
NSLog(@"%f", screenHeight);
if (isPortrait){
Y = (screenHeight-(0.14*screenHeight));
}else{
}
} else {
if (isPortrait){
Y = (screenHeight-(0.25*screenHeight));
}else{
}
}
settingsButton.frame = CGRectMake(20, Y, 40, 40.0);
aboutButton.frame = CGRectMake(75, Y, 40, 40.0);
있습니다 거기 많은 솔루션은,하지만 난 그렇게 선명하지 않다.
=====
매트 노이 부르크 나를 안내
[self.view addSubview:ab];
[self.view addSubview:sb];
//constraints
NSLayoutConstraint *constraint =[NSLayoutConstraint
constraintWithItem:ab
//ab's relation to the left edge
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeading
multiplier:1.0f
constant:7.f];
[self.view addConstraint:constraint];
constraint = [NSLayoutConstraint
constraintWithItem:ab
//ab's relation to the bottom edge
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0f
constant:-10.f];
[self.view addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:sb
//sb's identical relation to the bottom edge (violation of DRY but I'm in a hurry :'(//
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view attribute:NSLayoutAttributeBottom
multiplier:1.0f constant:-10.f];
[self.view addConstraint:constraint];
constraint = [NSLayoutConstraint
//SB's relation to the leading edge
constraintWithItem:sb
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeading
multiplier:1.0f
constant:75.0f];
[self.view addConstraint:constraint];
그리고이 결과 : NSLayoutConstraint을 고려 ... 이것은 내가 소집 무엇
솔직히
매트! 제약이 핵심이었다. – Morkrom