Method: UIView#tumble_in
- Defined in:
- lib/sugarcube-animations/uiview.rb
#tumble_in(options = {}, more_options = {}, &after) ⇒ Object
Moves the view on screen while slowly rotating it.
Based on https://github.com/warrenm/AHAlertView/blob/master/AHAlertView/AHAlertView.m
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/sugarcube-animations/uiview.rb', line 499 def tumble_in(={}, ={}, &after) if .is_a? Numeric default_duration = = side = [:side] || :left elsif .is_a? Symbol side = = default_duration = 0.3 else default_duration = 0.3 side = [:side] || :left end case side when :left angle = -Math::PI/4 when :right angle = Math::PI/4 else raise "Unknown direction #{side.inspect}" end reset_transform = self.transform reset_center = self.center [:duration] ||= default_duration unless .key?(:options) || .key?(:curve) [:options] = UIView.(curve: UIViewAnimationOptionCurveEaseOut) end [:after] = after window = UIApplication.sharedApplication.windows[0] top = self.convertPoint([0, 0], toView:nil).y height = window.frame.size.height - top offset = CGPoint.new(0, height * -1.5) offset = CGPointApplyAffineTransform(offset, self.transform) self.transform = CGAffineTransformConcat(self.transform, CGAffineTransformMakeRotation(angle)) self.center = CGPointMake(self.center.x + offset.x, self.center.y + offset.y) self.animate() do self.transform = reset_transform self.center = reset_center end end |