I want to know why you are unable to change the XY position of some objects in objective-c? For example... I had a toolbar with the following code, but it ONLY works if I place it WITHIN a UIView and then set the same coordinates... Can anyone explain why?
Doesn't Work:
UIToolbar *commentstoolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 400, 320, 44)];
[self.view addSubview:commentstoolbar];
Does Work:
UIToolbar *commentstoolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIView *toolbarView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 44)];
[toolbarView addSubview:commentstoolbar];
[self.view addSubview:toolbarView];
The UIToolbar conforms to the UIBarPositioning protocol, which specifies:
The UIBarPositioning protocol defines the ways that bars can be positioned on iOS devices. Bars can be positioned at the bottom of their enclosing view, at the top of their enclosing view, or at both the top of their enclosing view and also the top of the screen.
So the way to solve place a Tool bar anywhere is to enclose it in a view, just as you are doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With