Iphone 方向中的UIButton出现问题
我有一个按钮,我需要找到它的每个方向在不同的位置。 给你Iphone 方向中的UIButton出现问题,iphone,objective-c,orientation,Iphone,Objective C,Orientation,我有一个按钮,我需要找到它的每个方向在不同的位置。 给你 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation== UIInterfaceOrientationPortrait || interfaceOrientation== UIInterfaceOrientationPortraitDown) button.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation== UIInterfaceOrientationPortrait || interfaceOrientation== UIInterfaceOrientationPortraitDown)
button.frame=CGRectMake(150.0f,150.0f,55.0f,55.0f);
else
button.frame=CGRectMake(100.0f,100.0f,55.0f,55.0f);
return YES;
}
当我再次旋转IPad时,按钮转到另一个位置。
例如,在UIInterfaceOrientationPortrait中,按钮不在此处(150.0f、150.0f、55.0f、55.0f) 如何解决此问题?
谢谢您的帮助。方法中参数的名称是
interface-orientation
,但您正在检查方向。您应该检查接口方向
:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitDown) {
button.frame = CGRectMake(150.0f, 150.0f, 55.0f, 55.0f);
}
else {
button.frame = CGRectMake(100.0f, 100.0f, 55.0f, 55.0f);
return YES;
}
}
您正在检查UIInterfaceOrientationGraphitation
和UIInterfaceOrientationGraphitationDown
但是正确的枚举名称是UIInterfaceOrientationGraphicalUpsideDown
见:
你说“去另一个地方”是什么意思?UIInterfaceOrientationGraphitalDown根本不存在。还有一个错误粘贴从OP?我放弃了这一点,如果OP连他的代码都不能完整地呈现给我们,那么这就是问题所在吗?你修好了,现在可以用了?还是你只是吃错了?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation== UIInterfaceOrientationPortrait || interfaceOrientation== UIInterfaceOrientationPortraitUpsideDown)
button.frame=CGRectMake(150.0f,150.0f,55.0f,55.0f);
else
button.frame=CGRectMake(100.0f,100.0f,55.0f,55.0f);
return YES;
}