2012-06-26 58 views
0

我有一個帶有圖像的滾動視圖。用戶可以觸摸滾動視圖並在其上放置矩形視圖。我希望當用戶捏縮放滾動視圖時,子視圖應根據比例自動調整大小。另外,用戶應該能夠通過觸摸事件移動或調整子視圖的大小。當滾動視圖不放大但滾動視圖放大時,這可以正常工作,那麼當整個滾動視圖移動時,子視圖不能被調整大小或拖動。我試圖根據滾動視圖大小更改子視圖的框架大小,但它沒有給出正確的結果。如何在放大iphone時調整滾動視圖的子視圖sdk

有什麼辦法才能收到觸摸事件時滾動視圖被放大

在此先感謝

回答

0
@interface UIZoomingViewController : UIViewController <UIScrollViewDelegate> 
    @property (strong, nonatomic) UIView* substrate; 
@end 

@implementation UIZoomingViewController 

-(id)init /*your init method*/ 
{ 
    if(self = [super init]) 
    { 
     UIScrollView* scrollView = ((UIScrollView*)self.view); /*controller view - UIScrollView*/ 
     [scrollView setDelegate:self]; 
     /*set contentsize, min max zoom scale*/ 

     _substrate = [UIView alloc] initWithFrame:scrollView.bounds]; 
     [scrollView addSubview:_substrate]; 

     /* 
      if you need zoom view, add to substrate 
      [_substrate addSubview:...]; 
     */ 
    } 
    return self; 
} 

#pragma mark - UIScrollView delegate implementation 

-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView 
{ 
    return _substrate; 
} 

@end 

和小竅門,如果你需要的UIScrollView後接收觸摸,創建子類..

@interface UINewScrollView : UIScrollView 
@end 

@implementation UINewScrollView 

-(BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view 
{ 
    return YES; 
} 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [[self nextResponder] touchesBegan:touches withEvent:event]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [[self nextResponder] touchesMoved:touches withEvent:event]; 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [[self nextResponder] touchesEnded:touches withEvent:event]; 
} 

@end 
+0

@ NOMAD:它在子視圖在同一個類中時有效。但是我的子視圖是其他UIVIEW類的子類, itouch方法從其他類中使用。此外,該子視圖不只是在滾動視圖縮放時才觸摸,否則其工作正常 –

+0

需要一些代碼...) –

+0

@ nomad我做了這個,只是當用戶觸摸子視圖時,縮放scrollview滾動禁用 –

相關問題