2013-10-16 11 views
6

Tôi muốn tạo ra hình ảnh động mềm giữa hiệu ứng chuyển tiếp trong chỉ đơn giản là giao diện người dùng:mềm cuộn hoạt hình NSScrollView scrollToPoint:

first slidesecond slidethird slide

điểm cho rằng chuyển

view

Khi có cuộc gọi scrollToPoint: cho chế độ xem di chuyển đến điểm chuyển tiếp đó không hoạt ảnh. Tôi mới trong lập trình Cocoa (iOS là nền của tôi). Và tôi không biết cách sử dụng đúng .animator hoặc NSAnimationContext.

Ngoài ra tôi đã đọc hướng dẫn Hoạt ảnh cốt lõi nhưng không tìm thấy giải pháp.

Các nguồn có thể được truy cập trên Git Hub repository

Xin giúp !!!

Trả lời

16

scrollToPoint không hoạt động. Chỉ các thuộc tính có khả năng hoạt hình như giới hạn và vị trí trong NSAnimatablePropertyContainer mới hoạt ảnh. Bạn không cần phải làm bất cứ điều gì với CALayer: loại bỏ các công cụ wantLayer và CALayer. Sau đó, với mã sau nó được hoạt hình.

- (void)scrollToXPosition:(float)xCoord { 
    [NSAnimationContext beginGrouping]; 
    [[NSAnimationContext currentContext] setDuration:5.0]; 
    NSClipView* clipView = [_scrollView contentView]; 
    NSPoint newOrigin = [clipView bounds].origin; 
    newOrigin.x = xCoord; 
    [[clipView animator] setBoundsOrigin:newOrigin]; 
    [_scrollView reflectScrolledClipView: [_scrollView contentView]]; // may not bee necessary 
    [NSAnimationContext endGrouping]; 
} 
+0

Cảm ơn bạn! Nó hoạt động! Nhưng làm thế nào tôi có thể biết là tài sản có thể hoạt hình hay không? – WINSergey

-1

Cảm ơn, @mahal tertin Trong Swift

func scrollToPosition(pos:CGFloat){ 
    NSAnimationContext.beginGrouping() 
    NSAnimationContext.currentContext().duration = 0.5 
    var clip:NSClipView! 
    clip = self.scrollView.contentView 
    var newOrigin:NSPoint = clip.bounds.origin 
    newOrigin.x = pos 
    clip.animator().setBoundsOrigin(newOrigin) 
    self.scrollView.reflectScrolledClipView(self.scrollView.contentView) 
    NSAnimationContext.endGrouping() 
} 

Nó sẽ giúp dev mới !!!!!

Các vấn đề liên quan