Permalink
Browse files

add smoother animation on bad words

  • Loading branch information...
1 parent 95eb337 commit 021b94a70c6dd82e007719f0916a88e962924623 @mortenjust committed Oct 30, 2016
Showing with 31 additions and 17 deletions.
  1. BIN .DS_Store
  2. +2 −1 Simpler/SimplerTextView.swift
  3. +29 −16 Simpler/ViewController.swift
View
BIN .DS_Store
Binary file not shown.
@@ -43,7 +43,8 @@ class SimplerTextView: NSTextView, SimplerTextStorageDelegate {
func simplerTextStorageGotComplexWordAtRange(_ range:NSRange) {
- simplerDelegate.simplerTextViewGotComplexWord()
+ //simplerDelegate.simplerTextViewGotComplexWord()
+ // so to not duplicate the effect
if(UserDefaults.standard.bool(forKey: C.PREF_FORCESELECT)){
setSelectedRange(range)
@@ -91,43 +91,56 @@ class ViewController: NSViewController, SimplerTextViewDelegate {
}
func simplerTextViewGotComplexWord() {
+ print("got complex")
playBeginAnimation { () -> Void in
- self.playEndAnimation({ () -> Void in })
+ self.playMiddleAnimation({ () -> Void in
+ self.playEndAnimation {
+ //
+ }
+ })
}
makeBadSound()
}
func playBeginAnimation(_ completion:@escaping ()->Void){
- editorScrollView.wantsLayer = true
- editorScrollView.layerContentsRedrawPolicy = .onSetNeedsDisplay
-
+ print("start animation")
NSAnimationContext.runAnimationGroup({ (context) in
- // let's do this
- win.animator().setFrameOrigin(win.frame.offsetBy(dx: 3, dy: 0).origin)
+ context.duration = 0.10
+ let f = win.frame
+ let fo = win.frame.origin
+ win.animator().setFrame(NSMakeRect(fo.x+10, fo.y, f.width, f.height), display: true)
}, completionHandler: {
- // when done
completion()
})
}
- func playEndAnimation(_ completion:@escaping ()->Void){
- editorScrollView.wantsLayer = true
- editorScrollView.layerContentsRedrawPolicy = .onSetNeedsDisplay
-
+ func playMiddleAnimation(_ completion:@escaping ()->Void){
+ print("end animation")
NSAnimationContext.runAnimationGroup({ (context) in
- // let's do this
- context.duration = 0.30
-
- win.animator().setFrameOrigin(win.frame.offsetBy(dx: -3, dy: 0).origin)
+ context.duration = 0.10
+ let f = win.frame
+ let fo = win.frame.origin
+ win.animator().setFrame(NSMakeRect(fo.x-20, fo.y, f.width, f.height), display: true)
}, completionHandler: {
- // when done
completion()
})
}
+ func playEndAnimation(_ completion:@escaping ()->Void){
+ print("end animation")
+ NSAnimationContext.runAnimationGroup({ (context) in
+ context.duration = 0.10
+ let f = win.frame
+ let fo = win.frame.origin
+ win.animator().setFrame(NSMakeRect(fo.x+10, fo.y, f.width, f.height), display: true)
+ }, completionHandler: {
+ completion()
+ })
+ }
+
func simplerTextViewKeyUp(_ character: String) {

0 comments on commit 021b94a

Please sign in to comment.