CATransition on NSSplitView replaceSubview

  • Hello All.

    In the absence of IB functionality on transitions I am trying to set
    up a dissolve
    when replacing an NSSPlitView subview.
    The code below has been adapted from http://developer.apple.com/samplecode/CocoaSlides/
    .
    The subview is replaced but no animation occurs.

    If I use IB to turn on layering for the view class it does work!
    So must [self setWantsLayer:YES] be set elsewhere?
    And does it have to be set on all the subviews too?

    Thanks in advance

    Jonathan

    @interface MGSMotherWindowSplitview : NSSplitView {

    }
    - (void)updateSubviewsTransition;
    - (void)replaceTopView:(NSView *)newView;
    @end

    #import "MGSMotherWindowSplitview.h"
    #import <QuartzCore/CAAnimation.h>
    #import <QuartzCore/CoreImage.h>

    @implementation MGSMotherWindowSplitview

    - initWithFrame:(NSRect)newFrame {
        self = [super initWithFrame:newFrame];
        if (self) {
    [self setWantsLayer:YES];
            [self updateSubviewsTransition];
        }
        return self;
    }

    - (void)updateSubviewsTransition {
    CATransition *transition = [CATransition animation];
    [transition setType:kCATransitionFade];
    [transition setSubtype:kCATransitionFromLeft];
    [transition setDuration:1.0];
    [self setAnimations:[NSDictionary dictionaryWithObject:transition
    forKey:@"subviews"]];
    }

    - (void)replaceTopView:(NSView *)newView
    {
    [[self animator] replaceSubview:[[self subviews] objectAtIndex:0]
    with:newView];
    }

    @end
  • transitions only work if the view is layer backed.

    So you have to turn it on. turning it on for a view enables it for all
    the descending views, so no.

    As to where it is turned on in CocoaSlides, try the find command in
    Xcode. :-)

    SlideshowWindowControllerlm.m

    On Jan 13, 2008, at 7:22 PM, <jonathan...> wrote:

    > Hello All.
    >
    > In the absence of IB functionality on transitions I am trying to set
    > up a dissolve
    > when replacing an NSSPlitView subview.
    > The code below has been adapted from http://developer.apple.com/samplecode/CocoaSlides/
    > .
    > The subview is replaced but no animation occurs.
    >
    > If I use IB to turn on layering for the view class it does work!
    > So must [self setWantsLayer:YES] be set elsewhere?
    > And does it have to be set on all the subviews too?
    >
    > Thanks in advance
    >
    > Jonathan
    >
    > @interface MGSMotherWindowSplitview : NSSplitView {
    >
    > }
    > - (void)updateSubviewsTransition;
    > - (void)replaceTopView:(NSView *)newView;
    > @end
    >
    >
    > #import "MGSMotherWindowSplitview.h"
    > #import <QuartzCore/CAAnimation.h>
    > #import <QuartzCore/CoreImage.h>
    >
    >
    > @implementation MGSMotherWindowSplitview
    >
    > - initWithFrame:(NSRect)newFrame {
    > self = [super initWithFrame:newFrame];
    > if (self) {
    > [self setWantsLayer:YES];
    > [self updateSubviewsTransition];
    > }
    > return self;
    > }
    >
    > - (void)updateSubviewsTransition {
    > CATransition *transition = [CATransition animation];
    > [transition setType:kCATransitionFade];
    > [transition setSubtype:kCATransitionFromLeft];
    > [transition setDuration:1.0];
    > [self setAnimations:[NSDictionary dictionaryWithObject:transition
    > forKey:@"subviews"]];
    > }
    >
    > - (void)replaceTopView:(NSView *)newView
    > {
    > [[self animator] replaceSubview:[[self subviews] objectAtIndex:0]
    > with:newView];
    > }
    >
    >
    > @end
  • Hello Scott

    Thanks for the reply, and the hot find tip ;-)

    I have not figured out why but the animation works if [self
    setWantsLayer:YES] is moved
    from the view - initWithFrame:newFrame and is called from the window
    controller - windowDidLoad.
    The receiver is just getting the message after the nib has loaded.

    Which, of course, is what the CocoaSlides demo does.

    Reading the core animation docs didn't hurt either!

    Thanks again

    Jonathan

    On 14 Jan 2008, at 01:31, Scott Anguish wrote:

    > transitions only work if the view is layer backed.
    >
    > So you have to turn it on. turning it on for a view enables it for
    > all the descending views, so no.
    >
    > As to where it is turned on in CocoaSlides, try the find command in
    > Xcode. :-)
    >
    > SlideshowWindowControllerlm.m
    >
    > On Jan 13, 2008, at 7:22 PM, <jonathan...> wrote:
    >
    >> Hello All.
    >>
    >> In the absence of IB functionality on transitions I am trying to
    >> set up a dissolve
    >> when replacing an NSSPlitView subview.
    >> The code below has been adapted from http://developer.apple.com/samplecode/CocoaSlides/
    >> .
    >> The subview is replaced but no animation occurs.
    >>
    >> If I use IB to turn on layering for the view class it does work!
    >> So must [self setWantsLayer:YES] be set elsewhere?
    >> And does it have to be set on all the subviews too?
    >>
    >> Thanks in advance
    >>
    >> Jonathan
    >>
    >> @interface MGSMotherWindowSplitview : NSSplitView {
    >>
    >> }
    >> - (void)updateSubviewsTransition;
    >> - (void)replaceTopView:(NSView *)newView;
    >> @end
    >>
    >>
    >> #import "MGSMotherWindowSplitview.h"
    >> #import <QuartzCore/CAAnimation.h>
    >> #import <QuartzCore/CoreImage.h>
    >>
    >>
    >> @implementation MGSMotherWindowSplitview
    >>
    >> - initWithFrame:(NSRect)newFrame {
    >> self = [super initWithFrame:newFrame];
    >> if (self) {
    >> [self setWantsLayer:YES];
    >> [self updateSubviewsTransition];
    >> }
    >> return self;
    >> }
    >>
    >> - (void)updateSubviewsTransition {
    >> CATransition *transition = [CATransition animation];
    >> [transition setType:kCATransitionFade];
    >> [transition setSubtype:kCATransitionFromLeft];
    >> [transition setDuration:1.0];
    >> [self setAnimations:[NSDictionary dictionaryWithObject:transition
    >> forKey:@"subviews"]];
    >> }
    >>
    >> - (void)replaceTopView:(NSView *)newView
    >> {
    >> [[self animator] replaceSubview:[[self subviews] objectAtIndex:0]
    >> with:newView];
    >> }
    >>
    >>
    >> @end
    >
previous month january 2008 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