Fel*_*zin 9 objective-c uikit uiwindow ios ios7
我目前正在修复一个旧应用程序(在iOS 5时代内置)中的问题,其中按钮触摸事件在屏幕底部被忽略.我能够通过创建一个新项目,删除故事板(以及Info plist中的引用)来重新创建这个问题,并在didFinishLaunchingWithOptions中执行以下操作(我知道这不是正确的方法,但这个应用程序我'我正在进行类似的设置)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
self.window.screen = [UIScreen mainScreen];
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor yellowColor];
self.window.rootViewController = vc;
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test setTitle:@"Hey" forState:UIControlStateNormal];
[test setBackgroundColor:[UIColor whiteColor]];
test.frame = CGRectMake(0, 824, 200, 200);
[vc.view addSubview:test];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
一旦我运行这个应用程序,"嘿"按钮只能按下它的上半部分.我感觉它与iOS 7状态栏有关,以及UI现在如何在它下面而不是在它下面.我尝试调整窗口的界限,但这没有用.我已经尝试了各种各样的东西来使这个按钮工作,但唯一有效的是隐藏状态栏.
任何人都有任何线索如何让这个按钮在这种情况下工作?
小智 0
我在 iPad 应用程序中尝试了您的代码,“测试”按钮仅在纵向模式下显示。
我使用以下代码使其出现在横向中,并为其操作添加了一个目标。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
self.window.screen = [UIScreen mainScreen];
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor yellowColor];
self.window.rootViewController = vc;
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[test setTitle:@"Hey" forState:UIControlStateNormal];
[test addTarget:self action:@selector(testTapped:) forControlEvents:UIControlEventTouchUpInside];
[test setBackgroundColor:[UIColor whiteColor]];
test.frame = CGRectMake(0, 824, 200, 200);
[vc.view addSubview:test];
[self.window makeKeyAndVisible];
return YES;
}
-(void)testTapped:(id)sender
{
// the button responder
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,自动调整蒙版大小是必要的,因为您有按钮的硬编码框架。我添加了“UIViewAutoresizingFlexibleTopMargin”,使其在横向和纵向中都可见。
还添加了按钮操作的目标,这是按钮响应所必需的。
希望能帮助到你。
归档时间: |
|
查看次数: |
1541 次 |
最近记录: |