Basic animation with NSView and subviews

I subclassed NSView to create a container view (which I called TRTransitionView), which is used to place two subzones. With the click of a button, I want to translate one view from the parent view and switch to another using the Core Animation transition type: kCATransitionPush. For the most part, I work as you expected ( here is the basic test project that I put together ).

The problem I see concerns resizing my window and then switching between my two views. After resizing the window, my routines will appear at seemingly random locations in my TRTransitionView. In addition, it seems that TRTransitionView is not stretched correctly and cuts off the contents of its subzones. Ideally, I would like subviews to snap to the upper left corner of my parent view at all times, and also expand to expand the size of the parent view.

The second problem is related to the NSTableView, which I posted in my first subtitle. When my window is resized and my TRTransitionView changes according to its new dimensions, my TableView seems to be changing its contents quite inconveniently (the whole table seems to crowd around), and the recently expanded space that the table now occupies seems to be " flash "(as if in an animation). Extremely hard to describe, but is there any way to stop this?

Here is my TRTransitionView class:

-(void) awakeFromNib { [self setWantsLayer:YES]; [self addSubview:[self currentView]]; transition = [CATransition animation]; [transition setType:kCATransitionPush]; [transition setSubtype:kCATransitionFromLeft]; [self setAnimations: [NSDictionary dictionaryWithObject:transition forKey:@"subviews"]]; } - (void)setCurrentView:(NSView*)newView { if (!currentView) { currentView = newView; return; } [[self animator] replaceSubview:currentView with:newView]; currentView = newView; } -(IBAction) switchToViewOne:(id)sender { [transition setSubtype:kCATransitionFromLeft]; [self setCurrentView:viewOne]; } -(IBAction) switchToViewTwo:(id)sender { [transition setSubtype:kCATransitionFromRight]; [self setCurrentView:viewTwo]; } 
+4
source share

Source: https://habr.com/ru/post/1309037/


All Articles