ios - position view relative to tab indicator -


i've been given ui uses uitabbarcontroller, , in 1 of tabbed viewcontrollers, view (an arrow uiimageview) needs positioned relative tab indicator (the arrow needs point down @ indicator, centered along x-axis). used basic math emulate position based on known variables, , works iphone/pod in both landscape , portrait orientations, fails on ipad (it's little far right in both orientations - seems worse in landscape might perception).

here's used:

int visiblewidth = self.view.frame.size.width; int tabbarsize = self.tabbarcontroller.tabbar.frame.size.width; int tabsize = tabbarsize / [self.tabbarcontroller.viewcontrollers count]; int tabposition = 2; // hint should point @ 3rd tab int arrowiconwidth = hinticon.image.size.width; int arrowiconheight = hinticon.image.size.height;  int tabemulationposition = visiblewidth / 2 - tabbarsize / 2; int taboffsetposition = tabemulationposition + ( tabsize * tabposition ); int iconposition = taboffsetposition + ( tabsize / 2 - arrowiconwidth / 2 ); 

is there better way trying "fake" math (maybe getboundingclientrect type method?) or math approach best bet, assuming there's correct-able flaw in i've got?

tyia

your math seems alright except 1 caveat: core graphics distances of type cgfloat not int. remember integer division works differently in c might expect:

int x = 5 / 2; // x == 2 

thus, replace ints cgfloats , divide 2.0 rather 2.

also, in ipad tab button not spaced evenly across whole bar have padding left , right. have fiddle finding suitable constant, or experimentally find reliable way calculate based on number of view controllers.

assuming fixed tab bar button width, calculate offset add x of image:

cgfloat tabsize =     fixed_tab_button_width * self.tabbarcontroller.viewcontrollers.count; cgfloat offset = (tabbarsize - tabsize) / 2.0; 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -