1

In my app I've a UITextView inside an UIView. In the UITextView there are a lot of read-only text and my UIView it's large like the screen width, but the height can't contain all content in the UITextView.

The first idea I got is to create a gesture and to start an animation to increase the dimension of UIView when the gesture is starting. This is a good idea, but I want to do something better.

I wanted to create a stuff like the Notification Center: in notification center I tap on the system bar, move my finger down and I see the content of this view, I want to replicate this on my app. In other words I want to expand the dimension of my UIView by drag my finger on the display. Does anyone knows if there are a library or a solution to do this?

Thank you

lucgian841
  • 1,830
  • 5
  • 34
  • 57
  • have you tried this : http://stackoverflow.com/questions/8460119/how-to-resize-uiview-by-dragging-from-its-edges – Teja Nandamuri Sep 11 '15 at 14:41
  • I tried it but it doesn't do what I mean... It's a stuff that can be useful for other app, but I will have the same behavior like the notification center of the operating system, can you help me to find something that do that stuff? – lucgian841 Sep 11 '15 at 15:23
  • Your question is a bit unclear to me... Possibly you would like to adopt UIKitDynamic? – Ducky Sep 11 '15 at 15:58
  • I will try to explain you what I mean: I've a small table view in which there are written in any row a product. If I've a lot of row, this row are invisible in a little table view, so I'm searching a controller that allows me to drag the bottom of the table view and expand it, so I can read all row. The behavior should be similar to the notification center: you put a finger on the clock and drag the bar from top to the bottom and it will display the notification center. I hope it's clear now – lucgian841 Sep 14 '15 at 07:49

1 Answers1

2

I found a solution. I use the UIGestureRecognizer and I expand/reduce the UIView, this is the code I did:

- (IBAction)handlePan:(id)sender {
    CGPoint translation;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    if (self.gestureRecognizer.state == UIGestureRecognizerStateBegan || self.gestureRecognizer.state == UIGestureRecognizerStateChanged) {
        translation = [self.gestureRecognizer translationInView:self.view];

        [self.gestureRecognizer setTranslation:CGPointMake(0, 0) inView:self.view];

        CGRect newFrame = self.draggableView.frame;

        newFrame.size.width = self.draggableView.frame.size.width;
        newFrame.size.height = self.draggableView.frame.size.height + translation.y;

        [self.draggableView setFrame:newFrame];
    } else if (self.gestureRecognizer.state == UIGestureRecognizerStateEnded || self.gestureRecognizer.state == UIGestureRecognizerStateCancelled) {
        if (self.draggableView.frame.size.height + translation.y < screenRect.size.height / 2) {
            [self.buttonCloseView setHidden:YES];
            [self.draggableView setFrame:frame];
        } else {
            [self.buttonCloseView setHidden:NO];
            CGRect initialFrame = screenRect;
            initialFrame.origin.x = 0;
            initialFrame.origin.y = screenRect.origin.y + 20;
            [self.draggableView setFrame:initialFrame];
        }
    }
}

I hope it can be useful for someone.

lucgian841
  • 1,830
  • 5
  • 34
  • 57