Sunday, July 11, 2010

Wall Paper Editor: editing text

The next stage now that I can move views around is to enable editing text.  I modified the text view editor nib so that it now includes a UITextView as a member.  I disabled editing and user interaction, and eliminated the scrollbars.  I sized it to the full size of the view.

Otherwise when the user attempted to drag the view, it would start editing instead.



 I have no scrolling, and the view itself has no interaction.  This way it is just a display for text.  I can programmatically control when it can be edited.

View Mover -- register taps


First the view mover was modified so that when a single tap is received it will call the proper routine in the delegate.
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touches count %d, event touches for my view %d",[touches count],
  [[event touchesForView:parentView] count]);
// Handle single tap.
if ([delegate respondsToSelector:@selector(singleTap:)])
{
for (UITouch *touch in touches)
{
if (touch.tapCount==1)
{
NSLog(@"Sending singleTap");
[delegate singleTap:currentView];
}
}
}
etc..


Controller use taps to set subview


Next the controller was modified so that it would call new routines on the subview to enable input.  First it would tell any current view to stop editing, and then tell the a subview (if one was selected) to start editing.  Note that because single taps are registered anywhere on the UIImageView, this means that selecting something outside your current subview will cause they editing to stop.
- (void) singleTap:(UIView *)subViewTapped
{
NSLog(@"Received single tap");

// Go ahead and stop.
[self.currentPinchView stopEditing];
for (TextDisplayView *view in self.currentViews)
{
if (view.view==subViewTapped)
{
self.currentPinchView=view;
[view selectForEditing];
break;
}
}
}



Subview respond to taps and enable input



Two new routines exist to handle stopping and starting the taps.  Just so that I can visually see something happening, I also change the alpha and background color as the sequence occurs.
- (void) selectForEditing
{
self.view.alpha=0.4;
self.view.userInteractionEnabled=true;
self.textView.userInteractionEnabled=true;
[self.textView becomeFirstResponder];
}
- (void) stopEditing
{
self.view.alpha=0.3;
self.view.backgroundColor=[UIColor greenColor];
[self.textView resignFirstResponder];
self.view.userInteractionEnabled=false;
self.textView.userInteractionEnabled=false;
}



Known Bugs


This has one major problem.  A view near the bottom will be hidden by the keyboard.  I need to change how things are displayed so that this does not occur.

No comments:

Post a Comment