Sunday, July 11, 2010

Lock screen maker: A movable view

For the next step I want to have multiple views that I can click on and move, or click and edit.

This will need to be a new class, which has some simple characteristics.

I made a subclass of UIView for this.  The UIView will respond to gestures.

To start with I looked at the Move Me example from Apple.


Tap will start editing the textfield in the UIView.

Hold and move

This will allow the view to be moved around the screen.

Pinch in or out

This will cause the view to grow or shrink

Double Tap

This will allow color and font editing through a separate dialog.

Step 1 A movable view

The first stage will be to create a simple class that can be moved.  I created a very elementary .nib file, it consists of a view with a text field that fills it.  I then created a corresponding class in the controller that does the following:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    // If the touch was in the placardView, move the placardView to its location
    if ([touch view] == self.view) {
        CGPoint location = [touch locationInView:self.view.superview ]; = location;      

That's all you need to have a touch move your view.  Of course this only does move, but it's a start.  Everything else in this class is a standard view controller.

I then modified my previous routine to do the following:

for (int i=0;i<10;i++)
TextDisplayView *testView=[[TextDisplayView alloc] init];
[self.view addSubview:testView.view];

This gives me 10 small white view that I can pick up and move.

No comments:

Post a Comment