2013-10-16 152 views
6

我想簡單的用戶界面來創建轉換之間的軟動畫:感動軟滾動動畫NSScrollView scrollToPoint:

view

first slidesecond slidethird slide

視圖當呼叫scrollToPoint:用於移動視圖以指示過渡不動畫。 我是可可編程的新手(iOS是我的背景)。我不知道如何正確使用.animator或NSAnimationContext。

此外,我被讀了核心動畫指南,但沒有找到解決方案。

源可以在Git Hub repository

請幫助來達成!

回答

16

scrollToPoint不具動畫性。只有動畫屬性,例如NSAnimatablePropertyContainer中的邊界和位置。你不需要對CALayer做任何事情:刪除wantsLayer和CALayer的東西。然後使用下面的代碼進行動畫。

- (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

謝謝!有用!但是我怎麼知道這個屬性是可以動畫的呢? – WINSergey

-1

感謝,@mahal tertin 在斯威夫特

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() 
} 

這將有助於新的開發!!!!!