我在这里搜索了很多,但似乎找不到我的问题的答案......
我有一个名为SubView的类,这个类有一个简单的功能,它可以显示或消失动画
它是这样的:
-(void)showAnimated:(BOOL)animated {
self.active = YES;
//Make topmost
[self.parentView bringSubviewToFront:self];
if (animated) {
[UIView animateWithDuration:0.5
delay:0.0f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.frame = self.originalFrame;
if (self.panningBlock) {
self.panningBlock(self.contentView.frame);
}
}
completion:^(BOOL finished){
}];
}
else {
self.frame = self.originalFrame;
if (self.panningBlock) {
self.panningBlock(self.contentView.frame);
}
}
其中 self.originalFrame 存储了 View 位置的原始值,如果确实相似则隐藏部分
-(void)hideAnimated:(BOOL)animated {
self.active = NO;
//Store the frame
CGRect _frame = self.frame;
//Set the view starting point
switch (self.showingLocation) {
case SubViewShowingLocationRight:
_frame.origin = CGPointMake(_frame.size.width, _frame.origin.y);
break;
case SubViewShowingLocationBottom:
_frame.origin = CGPointMake(_frame.origin.x, _frame.size.height);
break;
case SubViewShowingLocationLeft:
_frame.origin = CGPointMake(-_frame.size.width, _frame.origin.y);
break;
default:
break;
}
if (animated) {
[UIView animateWithDuration:0.5
delay:0.0f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.frame = _frame;
if (self.panningBlock) {
self.panningBlock(self.contentView.frame);
}
}
completion:^(BOOL finished){
}];
}
else {
self.frame = _frame;
if (self.panningBlock) {
self.panningBlock(self.frame);
}
}
[self.delegate didDismissSubView:self];
//// 所以动画发生在 self.frame = _frame 和 self.frame = self.originalFrame
我还有 self.panningBlock,这是父 View 可以提供的 block (它可以工作,因此它可以根据 subview 的帧变化调整自己。即 subview 有一个选择器,它从底部出现,我需要调整表格 View ,这样它就不会被选择器遮挡)
我所做的一个例子是
__weak MapViewController * weakSelf = self;
[weakSelf.placesView setPanningBlock:^(CGRect _frame){
if (weakSelf.placesView.isActive) {
CGRect mapFrame = weakSelf.mapView.frame;
mapFrame.origin.x = _frame.origin.x + _frame.size.width;
weakSelf.mapView.frame = mapFrame;
}
else {
CGRect mapFrame = weakSelf.mapView.frame;
mapFrame.origin.x = 0;
weakSelf.mapView.frame = mapFrame;
}
}];
如果 subview 看起来像动画一样插入,则父 View 向右移动
这就是理解所需的所有代码(这是我的第一个问题,所以请原谅这里的任何漫无目的)
重点是动画不会同时发生, 发生的情况是,正在进入的 View 比父 View 的进入速度要慢一些 他们不粘在一起,我真的不知道该怎么办......
顺便说一句:它们在动画第一次出现时确实粘在一起,但之后就不再粘在一起了..
有什么建议吗?
编辑 我现在给出一些图像来解释发生的事情
最佳答案
我这样说是因为实际上没有达到答案......
这里的问题是...... View 的总大小......
MAPVIEW 大小为 100%,而 tableview 大小为 80%...我将它们放在相同的动画上...所以它们的移动方式会有所不同,因为它们必须覆盖整个运动 1.0 秒左右的动画。 .
这个问题可以通过执行显式动画来解决...那里有一些库...我使用了一个破坏了我的项目的...所以我最终放弃了它...并采取了更多...补丁解决方案...放置背景颜色,以便掩盖运动...
此问题的解决方案是使用显式动画,并且对于每一帧...将两个 View 移动到同一点...
我希望这个“解决方案”对社区有所帮助..
关于ios - 同时对两个 UIView 进行动画处理(粘在一起),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14800024/