2013-10-10 30 views
-1

我有一個UIView。在這個視圖中,我添加了UIScrollView.And scrollview包含一個UIButton.Everything是通過編程創建的。最初scrollview的內容大小與視圖大小相同。用戶可以在內部拖動按鈕。現在如果按鈕到達角落或滾動視圖的任何一側。如果拖動的時間超過1秒,那麼scrollview的內容大小應該會增加。我不知道這種技術或使用哪種方法,我們可以得到它。請幫助我。任何提示將不勝感激。謝謝您。拖動對象時增加UIScrollView的內容大小

回答

0

您必須爲您的UIButton添加UIPangesture識別器。牧草識別器的句柄需要更改UIButton框架以及UIScrollview框架。以此示例倡議爲參考。

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; 
[myButton setUserInteractionEnabled:YES]; 
[myButton addGestureRecognizer:panGesture]; 

和你的手柄方法應該像現在這樣,

-(IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender 
    { 
    CGPoint translation = [sender translationInView:self.view]; 
    sender.view.center = CGPointMake(sender.view.center.x + translation.x, 
             sender.view.center.y + translation.y); 
    [sender setTranslation:CGPointMake(0, 0) inView:self.view]; 

    //And check sender x,y position with your `scrollview`,if it is crossed then you have to reset the `contentOffset` 
    // Do the calculation like this 
    if([sender.view.center].x>yourScrollviewXposition) 
    { 
    coordforX=([sender.view.center].x + translation.x); 
    coordforY=([sender.view.center].y + translation.y); 
//based on your calculated x, y position you have to calculate scrollview width and height 
    [yourScrollView setContentSize:CGSizeMake(width,height)]; 
    } 
} 
+0

但我不想改變按鈕的框架......只需要改變滾動視圖的內容大小... – h999

+0

現在我的更新檢查回答 – wesley

+0

這裏什麼是識別器?我指的是哪一類的實例?你是如何得到它的? – h999

相關問題