0

我使用 Storyboard 在 UITableViewController 的最顶部(导航栏下方)有一个 UIScrollView。UIScrollView 的默认大小是 320x50。当用户保持滚动视图至少 1 秒时,我希望 UIScrollView 获得两倍大(320x100),以便通过动画显示更多细节。如果可能,它正下方的 UITableView 应该使用它进行动画处理并向下移动 50。

当 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

    }
}
4

1 回答 1

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];
于 2012-12-20T03:15:32.057 回答