2010-11-21 32 views
18

Tôi đang sử dụng UIScrollView và sử dụng scrollRectToVisible: hoạt ảnh Điều này có hiệu quả đối với tôi. Nhưng tôi muốn di chuyển đến một vị trí từ từ để người dùng có thể nhận thấy hiệu ứng. Có thể không.iphone - UIScrollview - scrollRectToVisible với hoạt ảnh chậm

Tôi đang thử mã sau, nhưng không thành công.

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDuration:2.0]; 
[scrlView scrollRectToVisible:<<some cgrect>> animated:YES];    
[UIView commitAnimations];   
+0

có thể trùng lặp của [UIScrollView scrollRectToVisible ở tốc độ tùy chỉnh] (http://stackoverflow.com/questions/1558262/uiscrollview-scrollrecttovisible-at-custom-speed) – tbodt

Trả lời

55

Giải pháp này thực sự khá dễ dàng. Nếu bạn sử dụng [scrollView scrollRectToVisible:frame animated:YES], chế độ xem cuộn sẽ bắt đầu hoạt ảnh của riêng nó, do đó, để tạo hoạt ảnh với thời lượng của bạn, bạn phải sử dụng [scrollView scrollRectToVisible:frame animated:NO] trong hoạt ảnh của mình.

Nói cách khác: Thao tác này sẽ hoạt động.

[UIView animateWithDuration:3 
         delay:0 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ [scrollView scrollRectToVisible:frame animated:NO]; } 
       completion:NULL]; 
Các vấn đề liên quan