Custom UITabBarController on iPhone
I'm relatively new to Obj-C and haven't got to the stage of navigating with my eyes shut yet :)
I'm writing a custom tab bar class as an exercise to learn a bit more & I need it for a project I'm d开发者_如何学运维oing. My thinking is to create a normal UITabBarController and then hide the view and replace it with my own, this has worked so far and I have got the desired aesthetics in place. As you can see here,
The code that I used to get this can be seen at this gist. The problem I'm faced with is the touch event does not seem to fire. I thought at first it was because the button was in a UIImageView, so enabled user interaction, but still no luck!
I'd appreciate any help that will get me towards the problem. As I've said I'm relatively new to Obj-C so it may just be something simple I've missed out!
I suspect that if you are not receiving touch event it is because you have added a sub view outside of the bounds of the superview. If this is the case you will never receive touch event because the touch will never get into the superview and therefore will never get into your subview.
If this is the case, you could try adding the view to the Window instead.
I have recently created a custom tab bar. Here are a few thing I learnt:
You can override
drawRect
in a custom subclass of UITabbar (or perhaps in a category extension). However it is limited, you cant draw outside of the bounds of the tab bar.You can subclass UITabBar and add a custom subview. Be sure to set
self.clipsToBounds = NO
if your subview is bigger than the tabbar.The UITabbar adds its own subviews after it is created.
You can hook into the touch events in a custom subclass by setting
self.delegate = self
and implement the tabbar delegate methods.
I would keep going with implementing the tab bar from scratch, it will be a good learning experience like you said.
精彩评论