Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIButton在iPhone4上不起作用_Ios_Objective C_Iphone_Uibutton - Fatal编程技术网

Ios UIButton在iPhone4上不起作用

Ios UIButton在iPhone4上不起作用,ios,objective-c,iphone,uibutton,Ios,Objective C,Iphone,Uibutton,我正在通过编程创建一个UIButton,当我在iPhone6上发短信时,它几乎可以正常工作,但在iPhone5上它开始工作得更努力了,而在iPhone4/4s上它根本不工作。它的行为就像内部攻丝面积越来越小的设备。我想说的是,UI看起来是一样的,下面是我正在使用的代码: //add exit button dismisSignInViewButton = [[UIButton alloc] init]; dismisSignInViewButton.frame = CGRectMake([[UI

我正在通过编程创建一个UIButton,当我在iPhone6上发短信时,它几乎可以正常工作,但在iPhone5上它开始工作得更努力了,而在iPhone4/4s上它根本不工作。它的行为就像内部攻丝面积越来越小的设备。我想说的是,UI看起来是一样的,下面是我正在使用的代码:

//add exit button
dismisSignInViewButton = [[UIButton alloc] init];
dismisSignInViewButton.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width * 0.87, [[UIScreen mainScreen] bounds].size.height * 0.07, 31, 31);
dismisSignInViewButton.backgroundColor = [UIColor redColor];
[dismisSignInViewButton addTarget:self
                           action:@selector(dismisSignInViewButtonFunction)
                 forControlEvents:UIControlEventTouchUpInside];
[dismisSignInViewButton setBackgroundImage:[UIImage imageNamed:@"exitButton.png"] forState:UIControlStateNormal];
[self.view addSubview:dismisSignInViewButton];
[dismisSignInViewButton setEnabled:YES];
[dismisSignInViewButton setHidden:NO];
我还试着看看它是否在启用/不启用和隐藏属性的情况下工作,但它不工作,知道bug可能在哪里吗

答复:

错误在于我在导航栏下绘制的UIButton在我的例子中是透明的,因此我修改了添加按钮的方式,而不是将其添加到self.view中。我将其添加到keyWindow中,以便将其添加到顶部。以下是最终代码:

//add exit button
    dismisSignInViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
    dismisSignInViewButton.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width * 0.87, [[UIScreen mainScreen] bounds].size.height + [[UIScreen mainScreen] bounds].size.height * 0.07, 31, 31);
    dismisSignInViewButton.backgroundColor = [UIColor redColor];
    [dismisSignInViewButton addTarget:self
                               action:@selector(dismisSignInViewButtonFunction)
                     forControlEvents:UIControlEventTouchUpInside];
    [dismisSignInViewButton setBackgroundImage:[UIImage imageNamed:@"exitButton.png"] forState:UIControlStateNormal];
    [[UIApplication sharedApplication].keyWindow addSubview:dismisSignInViewButton];
    [dismisSignInViewButton setEnabled:YES];
    [dismisSignInViewButton setHidden:NO];

通常,最好使用UIButtonButtonWithType:而不是按钮上的alloc init。尝试我假设这是布局问题Hi Laur,您是否尝试过使用Xcode 6中的视图调试器来诊断问题?例如,您可能有一个透明视图,相对于可能覆盖按钮的屏幕大小进行定位?关于视图调试器的更多信息:您的代码假定UIScreen.mainScreen.bounds等于self.view.bounds。情况并非总是如此。@wildBillMunson我试过你的建议,所以我用你建议的“DismissionInviewButton.frame=CGRectMakeself.view.bounds.size.width*0.87,self.view.bounds.size.height*0.07,31,31;”替换了我的代码现在这个按钮没有出现在屏幕上。