iOS5 上带有自定义 UITabBarController 的奇怪操作
我是 iOS 编程的新手。在制作自定义 UITabbarController 时,我遇到了 iOS4 和 iOS5 之间奇怪的操作差异。如果有人有解决这个问题的想法,请告诉我我错过了什么。
我想要的就是这个。
- UITableView / UITabBarController
- 单击切换标签栏即使在滚动时也应该起作用。
- 双击(以及更多)应该可以识别。
UITabBarController + UITapGestureRecognizer + UITableView 与双击事件一起工作。
让我抓狂的是这个。
用于切换点击项的非常简单的单击事件,在 UITableView 滚动时点击时不会调用。相反,点击发生了变化滚动完成后。
这是我的做法。
我希望 UITabBar 能够识别双标签。双击时,将 UITableView 滚动到顶部。所以我做了一个带有Tab栏补充的项目。
- DoubleTapBarController(自定义 UITabBarController )
- 标签栏(UITabBar)
- 第一个 VC(自定义 UIViewController)
- 默认 UITabBarItem
- 第二个 VC(自定义和默认空白 UIViewController)
- 默认 UITabBarItem
在第一个视图/VC
- 普通表视图中添加了 *table Outlet-ed。
- DoubleTabBarController 发送消息时处理双击事件的自定义方法“doubleTapped”。
在 DoubleTabBarController 中,
- 继承 UITabBarController 并
- 在 viewDidLoad 事件中使用 UITapGestureRecognizer 协议设置手势(单击、双击),
- 用于点击操作的 tap1、tap2、tap3、tap4。
我尝试过的(但失败了)。
- 在单击/双击之间注释 requireGestureRecognizerToFail。没用。
- 评论整个双击识别器。它在滚动时起作用。但没有双击事件。
- 滚动时双击其他选项卡。它使单击事件在滚动时发送。但这也不能成为解决方案。
- (因为我怀疑设置手势是否会造成焦点问题 - 双击有时有效!)评论双击并将其替换为三次点击。在正确的时间发送三次点击事件。但默认的单击事件无法在正确的时间工作 - 就像添加的双击手势一样。
我的代码。
DoubleTabBarController.h
#import <UIKit/UIKit.h>
@interface DoubleTabBarController : UITabBarController <UITabBarDelegate>
- (id)init;
@end
DoubleTabBarController.m (部分)
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1)] autorelease];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
singleTap.cancelsTouchesInView = NO;
UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2)] autorelease];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
doubleTap.cancelsTouchesInView = NO;
[singleTap requireGestureRecognizerToFail:doubleTap];
[[self tabBar] addGestureRecognizer:singleTap];
[[self tabBar] addGestureRecognizer:doubleTap];
}
当前状态
我失去了解决这个问题的方向。请帮助我
:)我在 iOS 4.3 上遇到了同样的问题,但删除 UITabBarControllerDelegate 协议就解决了。 iOS 5.0 又出现了这种情况:(
I'm kind of newbie for iOS programming. While making custom UITabbarController, I got stuck with weird action difference between iOS4 and iOS5. If anyone have an idea for solve this problem, please let me know where i got missed.
What I wanted is this.
- UITableView / UITabBarController
- Single tap for switching tab bar should work even while scrolling.
- Double tap (and further more) should recognizable.
UITabBarController + UITapGestureRecognizer + UITableView work together with double tap event.
What make me crazy is this.
The very plain single tap event for switching tap item, isn't called at the time tapped while UITableView is scrolling. Instead, the tap changed after scrolling finished.
Here is how I did.
I want UITabBar to recognize double tab. When it double tapped, scroll UITableView to the top. So I made a project with Tab bar supplement.
- DoubleTapBarController ( Custom UITabBarController )
- Tab Bar (UITabBar)
- First VC (Custom UIViewController)
- default UITabBarItem
- Second VC (Custom and default blank UIViewController)
- default UITabBarItem
In First View / VC
- Plain Table view added with *table Outlet-ed.
- Custom Method 'doubleTapped' for process double tapped event when DoubleTabBarController send message.
In DoubleTabBarController
- inherit UITabBarController with protocol
- set gestures (single tap, double tap) with UITapGestureRecognizer at viewDidLoad event
- tap1, tap2, tap3, tap4 for tap actions.
What I tried (and failed).
- Comment requireGestureRecognizerToFail between single/double tap. Didn't work.
- Comment whole double tap recognizer. It works while scrolling. But there is no double tap event.
- Double tap other tab while scrolling. It makes single tap event send while scrolling. But it can't be the solution, too.
- (As I doubt if setting gesture make focus problem - double tap worked at time!) Comment double tap and replace it with triple tap. Triple tap event sent at correct time. But default single tap event didn't work at correct time - like double tap gesture added.
My Code.
DoubleTabBarController.h
#import <UIKit/UIKit.h>
@interface DoubleTabBarController : UITabBarController <UITabBarDelegate>
- (id)init;
@end
DoubleTabBarController.m (part)
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1)] autorelease];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
singleTap.cancelsTouchesInView = NO;
UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2)] autorelease];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
doubleTap.cancelsTouchesInView = NO;
[singleTap requireGestureRecognizerToFail:doubleTap];
[[self tabBar] addGestureRecognizer:singleTap];
[[self tabBar] addGestureRecognizer:doubleTap];
}
Current state
I lost my direction for solve this problem. Please help me :)
ps. I faced the same problem on iOS 4.3, but it was solved removing UITabBarControllerDelegate protocol. And it occurred again at iOS 5.0 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论