2013-10-16 49 views
0

我有問題。我有UIImageViewUIButtonUIView拖動UIButton時改變框架

enter image description here

當我移動UIButton如箭頭所示,我需要改變按鈕的幀UIImageView。當我拖動UIButton到頂部時,我需要旋轉UIImageView

我想我需要在UIButton中添加手勢。但我怎麼能計算UIImageView的新幀,當我拖動UIButton

謝謝

回答

1
@synthesize resizableImageView; 
@synthesize resizeButton; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [resizeButton addTarget:self action:@selector(startDraggableCorner) forControlEvents:UIControlEventTouchDown]; 
    [resizeButton addTarget:self action:@selector(stopDraggableCorner) forControlEvents:UIControlEventTouchUpInside]; 
} 
-(void)startDraggableCorner 
{ 
    gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(wasDragged:)]; 
    [[self view] addGestureRecognizer:gestureRecognizer]; 
} 
-(void)wasDragged:(UIPanGestureRecognizer*)gesture 
{ 
    CGRect imageFrame = [resizableImageView frame]; 
    imageFrame.size.height = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].y - imageFrame.origin.y; 
    imageFrame.size.width = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].x - imageFrame.origin.x; 
    [resizableImageView setFrame: imageFrame]; 
    CGRect buttonFrame = [resizeButton frame]; 
    buttonFrame.origin.x = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].x; 
    buttonFrame.origin.y = [[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].y; 
    [resizeButton setFrame:buttonFrame]; 

} 
-(void)stopDraggableCorner 
{ 
    [[self view] removeGestureRecognizer:gestureRecognizer]; 
} 

這(幾乎)成功在您的可調整大小的行爲。旋轉圖像,也許你可以檢查[[gesture valueForKey:@"_lastScreenLocation"] CGPointValue].y是否低於一定數量,然後調用方法旋轉圖像