2012-12-20 29 views
0

我在使用故事板的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 

    } 
} 
+0

什麼不工作? – foundry

+0

爲了通過動畫調整'self.featureScrollView'的大小,我會在什麼地方說'//使它變大'和'//使它變小'?我只是不確定在那裏做什麼。 –

回答

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]; 
+0

完美地工作,謝謝羅恩! –

+0

實際上,每當我嘗試使用'frame.size.height- = 50;使其更小時,'scrollview就會消失。儘管如此,使它變得更加完美無瑕。 –

+0

這很奇怪。發現它已經是什麼了? – Ron