0

I am trying to create a floating keypad in an app created with the SplitViewController. I am using Touches to select the keypad view, move it, and limit its bounds to the edge of the DetailViewController minus some specified boundary.

I can easily create the floating keypad in a single-view app, but in the SplitViewController app, each time I try to move the keypad it only moves a couple of pixels and then stops.

So, all I can conclude is that there is something about the SplitViewController that is causing the problem. Is there a fix or a workaround?

Here's the code:

BOOL dragging;
float startX = 0;
float startY = 0;
float marginLeft = 20;
float marginRight = 20;
float marginTop = 150;
float marginBottom = 75;

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    dragging = NO;
    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInView:touch.view];

    if ([[touch.view class] isSubclassOfClass:[UIView class]]) {
        if ([touch view] == keypadFloatView) {
            startX = touchLocation.x;
            startY = touchLocation.y;
            dragging = YES;
        }
    }
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    dragging = NO;
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInView:touch.view];

    if ([[touch.view class] isSubclassOfClass:[UIView class]]) {
        if ([touch view] == keypadFloatView) {
            if (dragging) {
                float moveViewW = keypadFloatView.frame.size.width;
                float moveViewH = keypadFloatView.frame.size.height;

                CGRect frame = keypadFloatView.frame;
                frame.origin.x = keypadFloatView.frame.origin.x + touchLocation.x - startX;
                frame.origin.y = keypadFloatView.frame.origin.y + touchLocation.y - startY;

                if (frame.origin.x < marginLeft) { frame.origin.x = marginLeft; }
                if (frame.origin.x > DEVICE_SIZE.width - marginRight - moveViewW) { frame.origin.x = DEVICE_SIZE.width - marginRight - moveViewW; }
                if (frame.origin.y < marginTop) { frame.origin.y = marginTop; }
                if (frame.origin.y > DEVICE_SIZE.height - marginBottom - moveViewH) { frame.origin.y = DEVICE_SIZE.height - marginBottom - moveViewH; }

                keypadFloatView.frame = frame;
             }
        }
    }
}
Michael Young
  • 414
  • 1
  • 7
  • 16

1 Answers1

0

Eureka. This code is okay. The problem was with the iPad DetailViewController screen size that was "fixed." I changed the size to "freeform" and defined it as 768 x 1024 and the problem disappeared. Actually, there was a remaining problem but of a different nature, namely the touches and subsequent movement sometimes resulted in the MasterViewController sliding in from the left-hand side. To fix that, I disabled the "gesture" default in the AppDelegate.

Michael Young
  • 414
  • 1
  • 7
  • 16