在Long Press Gesture上调整UIScrollView的大小

时间:2012-12-20 03:08:51

标签: ios xcode uiscrollview resize uigesturerecognizer

我在使用Storyboard的UITableViewController的顶部(位于导航栏下方)有一个UIScrollView。 UIScrollView的默认大小为320x50。当用户持有scrollView至少1秒时,我希望UIScrollView获得两倍大(320x100),以便通过动画显示其他详细信息。如果可能的话,它下方的UITableView应该使用它进行动画制作并向下移动50.

当UIScrollView处于较大的设置时,按住UIScrollView至少1秒将产生相反的动画,并且UIScrollView将动画回原始大小。

我该怎么做?提前谢谢你!这是我到目前为止所做的:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.featureScrollExpanded = NO;
    UILongPressGestureRecognizer* featureHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self  action:@selector (longHold:)];

    [featureHold setDelaysTouchesBegan : YES];
    featureHold.minimumPressDuration = 0.6;
    featureHold.numberOfTouchesRequired = 1;
    [self.featureScrollView addGestureRecognizer:featureHold];
    [featureHold release];
}

- (void)longHold:(UIGestureRecognizer*)sender {
    if (self.featureScrollExpanded==NO) {
        self.featureScrollExpanded=YES;
        //make it bigger

    }
    else {
        self.featureScrollExpanded=NO;
        //make it smaller

    }
}

1 个答案:

答案 0 :(得分:1)

做一个动画:

CGRect frame = yourScrollView.frame;
frame.size.height += 50;
[UIView animateWithDuration:0.6
                     animations:^{
                         yourScrollView.frame = frame;
                     } completion:^(BOOL finished) {
                            //do your other animation here if you want to 
                            //or do them both together and lose this block
                     }
     ];

或者如果您想要更多概述:

CGRect frame = yourScrollView.frame;
frame.size.height += 50;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.6];

[self.yourScrollView setFrame:frame];

[UIView commitAnimations];