Sunday, July 11, 2010

Wall Paper Editor: Dynamic toolbar.

OK, the next step is to change things so that instead of having an ugly button in the middle of the screen, I have a toolbar that can be shown or not show when the user does a single tap on the screen. This is a pretty common UI paradigm.

Creating toolbar in UIBuilder

First I created a toolbar in UIBuilder.  I could have done it dynamically, but this way I can hook everything up in UI builder.  Note because of the way I'm doing this, I can have multiple toolbars in UIbuilder and switch between them.

I hooked the toolbar up to the select picture, and added a new 'add text' window.
For now it's pretty simple, but I will likely expand it, and create better icons later.  I add events to my view controller for the various actions.

Changing creation of my classes

I change the creation of my views and variables so that I create a single view when the add button is chosen.  In addition I moved the creation of my various collections to viewDidLoad:

self.currentViews=[[NSMutableArray alloc]init];
NSMutableSet *viewSet=[[NSMutableSet alloc]init];

- (IBAction) addWindow:(id)sender
TextDisplayView *testView=[[TextDisplayView alloc] init];
[self.view addSubview:testView.view];
[self.currentViews addObject:testView];
[viewMoveHandler.childViews addObject:testView.view];

Intercepting single tap and displaying the toolbar

Next I intercept the single tap and when it arrives check to see if I'm in a view.  If so act as previously, otherwise toggle my toolbar.   Note that my toolbar has to be set to be at the bottom of the view, otherwise it appears at the top (since it's origin is 0,0).
I modified singleTap to handle this:

- (void) singleTap:(UIView *)subViewTapped
NSLog(@"Received single tap");

// Go ahead and stop.
[self.currentPinchView stopEditing];
        // existing code.
for (TextDisplayView *view in self.currentViews)
if (view.view==subViewTapped)
[view selectForEditing];
if (self.currentPinchView==nil)
if (windowControl.superview==nil)
CGRect rect=windowControl.frame;
[self.view addSubview:windowControl];
}else {
[windowControl removeFromSuperview];


No comments:

Post a Comment