在iPhone中我已經知道navigationbarbutton觸摸也有一些擴展在導航欄下,但我需要限制用戶交互只有一定的限制。我可以做到這一點。任何人都可以幫助我嗎?限制導航欄按鈕項中的觸摸區域?
1
A
回答
0
實現輕擊手勢識別器並將您的控制器設置爲委託。然後執行:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// [touch locationInView] -> gives the point where the user touched
// If the touch point belongs to your frame then return YES
// else return NO
}
0
可以實現自定義導航欄自己與隱藏的導航欄的「引擎」背後,讓按鈕上的自定義導航欄與所需的自定義行爲/視覺效果。 如果您想實現手勢邏輯(平移)切換導航頁面,這也很有用。
AppDelegate.h:
@property (strong, nonatomic) UINavigationController *navigationController;
AppDelegate.m:
YourMainViewController *yourmainViewController = [[YourMainViewController alloc] init];
_navigationController = [[UINavigationController alloc] yourmainViewController];
[_navigationController setNavigationBarHidden:TRUE];
[self.window setRootViewController:_navigationController];
[self.window makeKeyAndVisible];
YourMainViewController.m:實現自定義導航圖像和添加按鈕,您的視圖使用Interface Builder編程或導航無論是。例如編程方式創建視圖:
- (void)loadView {
...
UIImageView *tmp_mynavbar = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CustomNavBG.png"]];
tmp_mynavbar.frame = CGRectMake(0, 0, 320, 44);
[self.view addSubview:tmp_mynavbar];
UIButton *tmp_addbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmp_addbutton.frame = CGRectMake(260, 10, 40, 20);
[tmp_addbutton setTitle:@"Add" forState:UIControlStateNormal];
[tmp_addbutton setBackgroundImage:[UIImage imageNamed:@"CustomNavAddBtn.png"] forState:UIControlStateNormal];
[tmp_addbutton addTarget:self action:@selector(pressedbuttonAddItem:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tmp_addbutton];
// create button with the required size, user interaction area (add image then add transparent button with different size, etc)
// also add a back button
...
}
然後實現自定義導航按鈕行爲(添加/前進按鈕也後退按鈕)
-(void) pressedbuttonAddItem:(id) sender {
AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication] delegate];
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[[app navigationController] detailViewController animated:YES];
}
-(void) pressedbuttonBack:(id) sender {
AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication] delegate];
[[app navigationController] popViewControllerAnimated:YES];
}
相關問題
- 1. Cocos2d按鈕觸摸區域
- 2. 如何擴展按鈕觸摸區域?
- 3. 用sencha觸摸按鈕導航
- 4. 刪除邊框導航欄按鈕單點觸摸
- 5. 導航欄按鈕
- 6. 觸摸區域控制
- 7. 如何在iPad中擴展HTML5中的按鈕觸摸區域?
- 8. 限制在iPhone中的UIButton的可觸摸區域?
- 9. 限制按鈕的點擊區域
- 10. MaterializeCSS導航欄按鈕不觸發側導航
- 11. 按鈕不顯示在導航欄項
- 12. 禁用導航欄按鈕項目
- 13. IOS 11導航欄按鈕項目
- 14. iOS自定義導航欄按鈕項
- 15. 導航欄按鈕項目色調
- 16. 觸摸導航欄時隱藏鍵盤
- 17. 定製後退按鈕在導航欄
- 18. 定製導航欄隱藏按鈕
- 19. 欄按鈕項從導航控制器中消失
- 20. 按鈕排列在NavigationView的導航欄/停靠在煎茶觸摸
- 21. 導航菜單可點擊區域延伸過導航按鈕
- 22. 導航欄中的左欄按鈕項目
- 23. 在區域外彈出導航模式關閉觸摸事件
- 24. iPhone的Safari上的按鈕觸摸區域不同於iPad的
- 25. 導航欄和按鈕
- 26. 更改導航欄按鈕
- 27. jQuery和導航欄按鈕
- 28. 旋轉導航欄按鈕
- 29. iphone 2按鈕導航欄
- 30. 導航帶後退按鈕的左欄按鈕項目
一個快速的想法:使用可以把透明'UIView'所以你不能碰那部分! – Maulik 2013-03-14 07:40:17
@maulik我有一個按鈕只是在嘮叨bar.so當我觸摸該按鈕有時導航欄按鈕被調用... – hacker 2013-03-14 07:42:50
然後,我想你必須改變按鈕位置 – Maulik 2013-03-14 07:43:40