因此,我有一个正在设置的自定义容器视图控制器,并且我有一个自定义动画,假设您在子视图控制器之间滑动时会发生这种动画,该控制器运行良好,直到我将临时 UILabel 从占位符视图中取出并将子视图控制器中的视图添加到占位符。如果我注释掉“addSubview”行,那么动画就会再次完美运行,但很明显我没有孩子,这有点意思......
现在我说动画不起作用,但这并不完全正确,因为任何与我在 init 中添加的东西(即通知和用户占位符和子项)相关的东西都可以完美地动画。不过,提要视图在它们下方是可见的,并且页眉和页脚栏有时只会移动。如果我将触摸 y 轴和 x 移动到一起,它会随机抽搐……这很奇怪。
用于设置和添加子 VC 的初始化代码:
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
self.feedVC = (NiTActionFeedViewController*)[sb instantiateViewControllerWithIdentifier:@"Feed"];
self.feedVC.delegate = self;
[self addChildViewController:self.feedVC];
self.feedVC.view.frame = self.mainPage.bounds;//mainPage view is the only UIView that is placed in the IB as template for the other views (so I don't have to worry about resizing for 4" retina^^;)
[self.mainPage addSubview:self.feedVC.view];
[self.feedVC didMoveToParentViewController:self];
//notify
self.notifyPage = [[UIView alloc] initWithFrame:CGRectOffset(self.mainPage.frame, -kPageShift, 0)];// this is one of the placeholder views
[self.notifyPage setClipsToBounds:YES];
self.notifyVC = (NiTNotificationViewController*)[sb instantiateViewControllerWithIdentifier:@"Notify"];
self.notifyVC.delegate = self;
[self addChildViewController:self.notifyVC];
self.notifyVC.view.frame = self.notifyPage.bounds;
[self.notifyPage addSubview:self.notifyVC.view];
[self.notifyVC didMoveToParentViewController:self];
//user
self.userPage = [[UIView alloc] initWithFrame:CGRectOffset(self.mainPage.frame, kPageShift, 0)];
[self.userPage setClipsToBounds:YES];
self.userVC = (NiTUserViewController*)[sb instantiateViewControllerWithIdentifier:@"UserScreen"];
self.userVC.delegate = self;
[self addChildViewController:self.userVC];
self.userVC.view.frame = self.userPage.bounds;
[self.userPage addSubview:self.userVC.view];
[self.userVC didMoveToParentViewController:self];
[self.view addSubview:self.notifyPage];
[self.view addSubview:self.userPage];
//and then re-add the header and footer views so that the children don't cover them^^
[self.view addSubview:self.headerbar];
[self.view addSubview:self.headerButton];
[self.view addSubview:self.footerbar];
[self.view addSubview:self.footerButton];
[self.view addSubview:self.rightPageIndicator];
[self.view addSubview:self.leftPageIndicator];
这是touchesMoved代码(如果您需要更多代码,请告诉我,但即使最后他们也不让步):
if (touches.count > 0) {
UITouch* touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
float diff = currentPoint.x - startingPoint.x;
//currentScreen is an enum that I set on load and on trigger of the screen change so I always know what screen is showing and it is always accurate
//this line is just to make sure we don't go past the "edge" of the screen and is working perfectly
if ((self.currentScreen - (diff<0?-1:1)) > userScreen||(self.currentScreen - (diff<0?-1:1)) < notifScreen) {
return;
}
self.headerbar.frame = CGRectOffset(initheaderbar, (int)(kHeaderBarShift * (diff/kPageShift)), 0);
self.headerButton.frame = CGRectOffset(initheaderButton, kHeaderButtonShift * (diff/kPageShift), 0);
self.footerbar.frame = CGRectOffset(initfooterbar, kFooterBarShift * (diff/kPageShift), 0);
self.mainPage.frame = CGRectOffset(initmainPage, kPageShift * (diff/kPageShift), 0);
self.userPage.frame = CGRectOffset(inituserPage, kPageShift * (diff/kPageShift), 0);
self.notifyPage.frame = CGRectOffset(initnotifyPage, kPageShift * (diff/kPageShift), 0);
//this always updates and looks right even though nothing changes on the screen
NSLog(@"move main:%@(%@)\nnotify:%@\nuser: %@",NSStringFromCGRect(CGRectOffset(initmainPage, kPageShift * (diff/kPageShift), 0)),NSStringFromCGRect(self.mainPage.frame),NSStringFromCGRect(CGRectOffset(initnotifyPage, kPageShift * (diff/kPageShift), 0)),NSStringFromCGRect(CGRectOffset(inituserPage, kPageShift * (diff/kPageShift), 0)));
lastPoint = currentPoint;
}else{
//never seen this called thus why I have it here so I know if something mind blowing has happened
NSLog(@"W.T.F");
}
现在,您可能需要知道的最后一点是,我设置了一个“touchController”协议,该协议可以在所有指向父级的子级中设置“touchDelegates”,以便他们收到的任何触摸都会转发到容器VC,他们都在正确转发,所以不是这样(如果是这种情况,动画根本不起作用)......
帮助我欧比旺克诺比,你是我唯一的希望!说真的,可以使用任何人都可以提供的任何帮助^^;
要求的信息 我几乎为屏幕上的所有内容设置动画。由于项目的性质,我无法发布屏幕截图或视频,但希望您能够与我一起使用下面的图表(对不起,我不是 Photoshop 期望 =P)。图中唯一没有显示的是 headerButton,但基本上它只是在 headerBar 的顶部,并且移动速度稍慢,因为它没有移动那么远。该设计的理念是,如果您向一个方向滑动,它会向相反的方向滑动屏幕(如您所料),并且页眉和页脚栏以不同的速度滑动,因为它们更短,因此它们上的项目始终可见,但在显示您所在的一侧/页面时具有“酷”效果。(两个栏都不会在屏幕上显示“结束”,“结束” 直接到屏幕边缘,但从不出现)所有的常量就是这样。kPageShift 是屏幕宽度 (320)。剩下的就是它们需要在屏幕之间移动多远,因为除了页面之外它们的大小都不同。如果您需要更多信息,请告诉我!