This is the original layout: A UIBarButtonItem
displays a custom view inside a UIToolbar
:
+-- main view --------------+
| |
| |
| +-- toolbar ------------+ |
| | +-- custom view ----+ | |
| | | | | |
| | +-------------------+ | |
| +-----------------------+ |
+---------------------------+
Here is how I am doing this:
UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithCustomView:self.customView] autorelease];
NSArray* items = [NSArray arrayWithObject:button];
self.toolbar.items = items;
After some user interaction I want to remove the custom view from the toolbar and display it somewhere else, in this example directly as a subview of the main view:
+-- main view --------------+
| |
| +-- custom view ----+ |
| | | |
| +-------------------+ |
| |
| +-- toolbar ------------+ |
| | | |
| +-----------------------+ |
+---------------------------+
I am trying to do this like so (self
is a view controller):
self.toolbar.items = [NSArray array];
CGRect frame = self.customView.frame;
frame.origin.x = 10;
frame.origin.y = 10;
self.customView.frame = frame;
[self.view addSubview:self.customView];
This does not work. For some reason the custom view is not displayed after I move it to its new superview. I must be doing something wrong here, but I don't know what it is. Any hints?