Re: How to (slowly) rotate a view

  • On Mon, 06 Aug 2012 00:11:39 +0700, "Gerriet M. Denkmann" <gerriet...> said:
    > I use this code (iOS 5.1):
    > CGAffineTransform m = { c, +s, -s, c, 0, 0 };    //    rotation, s = sin(angle), c = cos(angle)
    > CALayer *layer = self.view.layer;    //    view is UIView, self is subclass of UIViewController
    > [ CATransaction begin];
    > [ CATransaction setAnimationDuration: 9 ];
    > [ layer setAffineTransform: m ];
    > [ CATransaction commit];
    > The view rotates ok, but does it instantly, instead of taking 9 seconds.
    >
    > What am I doing wrong?

    You are attempting to use implicit property animation (setAffineTransform:) on a view's primary layer. You can't do that; the property will change, but it won't animate. To get animation on that particular layer, you must use explicit animation (CABasicAnimation) or view animation. Explained here:

    http://www.apeth.com/iOSBook/ch17.html

    m.

    --
    matt neuburg, phd = <matt...>, <http://www.apeth.net/matt/>
    A fool + a tool + an autorelease pool = cool!
    Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
  • On 19 Aug 2012, at 00:18, Matt Neuburg <matt...> wrote:

    > On Mon, 06 Aug 2012 00:11:39 +0700, "Gerriet M. Denkmann" <gerriet...> said:
    >> I use this code (iOS 5.1):
    >> CGAffineTransform m = { c, +s, -s, c, 0, 0 };    //    rotation, s = sin(angle), c = cos(angle)
    >> CALayer *layer = self.view.layer;    //    view is UIView, self is subclass of UIViewController
    >> [ CATransaction begin];
    >> [ CATransaction setAnimationDuration: 9 ];
    >> [ layer setAffineTransform: m ];
    >> [ CATransaction commit];
    >> The view rotates ok, but does it instantly, instead of taking 9 seconds.
    >>
    >> What am I doing wrong?
    >
    > You are attempting to use implicit property animation (setAffineTransform:) on a view's primary layer. You can't do that; the property will change, but it won't animate. To get animation on that particular layer, you must use explicit animation (CABasicAnimation) or view animation. Explained here:
    >
    > http://www.apeth.com/iOSBook/ch17.html

    I am now using view animation (as explained in your book chapter 17 "Block-Based View Animation").
      [ UIView animateWithDuration: duration
              animations:    ^
                       {
          self.view.transform = newTransform;
                       }
      ];

    CABasicAnimation works as well, but requires more code.

    Kind regards,

    Gerriet.
previous month august 2012 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today