6
我使用UINavigationBar
和UITabBar
創建視圖。我在標籤欄上添加了一個按鈕,點擊按鈕時,我隱藏標籤欄並在底部顯示工具欄。我的代碼是爲當前以及之前的iOS版本編寫的。我使用此代碼爲self.edgesForExtendedLayout = UIRectEdgeNone;
這iOS7是我的代碼:UITabBar按鈕出現問題,TabBar按鈕變爲不可點擊
- (void)hideTabBar {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;enter code here
[UIView animateWithDuration:0.5
animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds);
tabBar.frame = tabFrame;
// CGRect contentFrame = content.frame;
// contentFrame.size.height -= tabFrame.size.height;
content.frame = window.bounds;
}];
if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
{
CGRect frame = tbl_AllFiles.frame;
frame.size.height -=tabBar.frame.size.height;
tbl_AllFiles.frame = frame;
}
}
- (void)showTabBar {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;
if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
{
CGRect frame = tbl_AllFiles.frame;
frame.size.height +=tabBar.frame.size.height;
tbl_AllFiles.frame = frame;
}
[UIView animateWithDuration:0.5
animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);
tabBar.frame = tabFrame;
CGRect contentFrame = content.frame;
contentFrame.size.height -= tabFrame.size.height;
content.frame = contentFrame;
}];
}
- (void)loadToolBar {
toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
moveButton = [UIButton buttonWithType:UIButtonTypeCustom];
[moveButton setFrame:CGRectMake(10, 10, 120, 25)];
[moveButton setBackgroundColor:[UIColor redColor]];
[moveButton setTitle:@"Move" forState:UIControlStateNormal];
[moveButton addTarget:self action:@selector(moveFile_Folder:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *moveItem = [[[UIBarButtonItem alloc] initWithCustomView:moveButton] autorelease];
moveItem.style = UIBarButtonItemStyleBordered;
NSArray *items = [NSArray arrayWithObjects:moveItem, nil];
toolbar.items = items;
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
CGRect mainViewBounds = self.view.bounds;
if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
{
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
}
else
{
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
}
[self.view addSubview:toolbar];
[toolbar bringSubviewToFront:self.view];
}
我的問題是按鈕點擊hideTabBar和loadToolBar方法被調用。一切工作正常,除了我的按鈕現在在工具欄上不可點擊。 請幫幫我。
,你有沒有試過SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@ 「7.0」) – DogCoffee
我使用。 if([[[UIDevice currentDevice] systemVersion] intValue]> = 7.0) self.edgesForExtendedLayout = UIRectEdgeNone; } –
是的,我知道爲什麼我向你展示了我認爲它是一個乾淨的方法來做同樣的事情。關於你的問題,你可以通過點擊按鈕來獲得NSLog嗎? – DogCoffee