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:


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



- (IBAction) addWindow:(id)sender
{
TextDisplayView *testView=[[TextDisplayView alloc] init];
testView.view.multipleTouchEnabled=true;
testView.view.frame=CGRectMake(0,0,40,40);
[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];
self.currentPinchView=nil;
        // existing code.
for (TextDisplayView *view in self.currentViews)
{
if (view.view==subViewTapped)
{
self.currentPinchView=view;
keyHelper.view=view.view;
[view selectForEditing];
break;
}
}
if (self.currentPinchView==nil)
{
if (windowControl.superview==nil)
{
CGRect rect=windowControl.frame;
rect.origin.x=0;
rect.origin.y=self.view.bounds.size.height-windowControl.frame.size.height;
windowControl.frame=rect;
[self.view addSubview:windowControl];
}else {
[windowControl removeFromSuperview];
}

}
}

No comments:

Post a Comment