2010-07-13 10 views

Trả lời

1

Sử dụng hoạt ảnh của UIView.

Đó là một chút dài để giải thích, vì vậy tôi hy vọng ví dụ nhỏ này sẽ xóa mọi thứ một chút. Nhìn vào documantation để được hướng dẫn thêm

[UIView beginAnimations: nil context: NULL]; 
[UIView setAnimationDuration: 2]; 
[UIView setAnimationDelegate: self]; 
[UIView setAnimationDidStopSelector: @selector(revertToOriginalDidStop:finished:context:)]; 

expandedView.frame = prevFrame; 

[UIView commitAnimations]; 

Nó từ một dự án tôi đang làm việc trên nên đó là một chút đặc biệt, nhưng tôi hy vọng bạn có thể thấy những điều cơ bản.

0

Tôi đã có may mắn với phương pháp này trong một lớp con UIScrollView:

- (void)zoomToRect:(CGRect)rect duration:(NSTimeInterval)duration 
{ 
    [self setZoomLimitsForSize:rect.size]; 

    if (duration > 0.0f) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 
     [UIView setAnimationDuration:duration]; 
    } 
    [self zoomToRect:rect animated:NO]; 
    if (duration > 0.0f) 
     [UIView commitAnimations]; 

    [self zoomToRect:rect animated:(duration > 0.0f)]; 
} 

Nó kinda gian lận, nhưng nó dường như chủ yếu là làm việc. Thỉnh thoảng nó thất bại, nhưng tôi không biết tại sao. Trong trường hợp này, nó chỉ trở lại tốc độ hoạt ảnh mặc định.

+2

Tôi đã gặp trường hợp 'thỉnh thoảng không thành công', khiến hoạt ảnh chạy ở thời lượng mặc định. Trường hợp này dường như xảy ra khi các kích thước trực tiếp trước đó và nhắm mục tiêu phù hợp, thậm chí thông qua nguồn gốc khác nhau. Đây là mã hoạt hình mới của tôi, thêm dòng scrollRectToVisible, và tôi không nhấn trường hợp lỗi này nữa. [UIView animateWithDuration: 2 delay: 0 options: UIViewAnimationOptionBeginFromCurrentState animations:^{ [scrollView scrollRectToVisible: target animated: NO]; [scrollView zoomToRect: target animated: NO]; } hoàn thành: nil]; – fionbio

+0

hay Nous tuyệt vời của nó !!! Nó hoạt động tốt Cảm ơn –

0

Thực ra những câu trả lời này thực sự gần với những gì tôi đã sử dụng nhưng tôi sẽ đăng bài riêng biệt vì nó khác. Về cơ bản zoomToRect không hoạt động chính xác nếu zoomScale đích giống với zoomScale hiện tại.

Bạn có thể thử scrollToRect nhưng tôi không có bất kỳ may mắn nào với điều đó.

Thay vì chỉ sử dụng contentOffset và đặt nó thành zoomRect.origin và lồng trong khối hoạt ảnh.

[UIView animateWithDuration:duration 
         delay:0.f 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
    if (sameZoomScale) { 
     CGFloat offsetX = zoomRect.origin.x * fitScale; 
     CGFloat offsetY = zoomRect.origin.y * fitScale; 

     [self.imageScrollView setContentOffset:CGPointMake(offsetX, offsetY)]; 
    } 
    else { 
     [self.imageScrollView zoomToRect:zoomRect 
           animated:NO]; 
    } 
       } 
       completion:nil];