ios – 找不到调整两个视图大小的数学公式

ios – 找不到调整两个视图大小的数学公式,第1张

概述我有一个你可以在我的素描上看到的起始位置.我的地图总是填满整个屏幕.我只是调整了我的tableview. 当我点击地图时,tableview会调整大小,就像你在我的秒画面上看到的那样.如果我然后单击tableview,则tableview会调整大小. 现在的问题是我找不到一个数学函数,即2个东西总是大小相等.就像我指出草图一样. 这是我如何初始化2个视图: -(void) initMapView 我有一个你可以在我的素描上看到的起始位置.我的地图总是填满整个屏幕.我只是调整了我的tablevIEw.

当我点击地图时,tablevIEw会调整大小,就像你在我的秒画面上看到的那样.如果我然后单击tablevIEw,则tablevIEw会调整大小.

现在的问题是我找不到一个数学函数,即2个东西总是大小相等.就像我指出草图一样.

这是我如何初始化2个视图:

-(voID) initMapVIEw{    _mapVIEw = [[GoogleMapVIEwController alloc] init];    [self addChildVIEwController:_mapVIEw];    _mapVIEw.vIEw.frame = CGRectMake(0,self.vIEw.bounds.size.wIDth,self.vIEw.bounds.size.height);    UILongPressGestureRecognizer * tapGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(expandMap:)];    [_mapVIEw.vIEw addGestureRecognizer:tapGesture];    [self.vIEw addSubvIEw:_mapVIEw.vIEw];    [_mapVIEw dIDMovetoParentVIEwController:self];}-(voID) initPOItableVIEw{    _poitableVIEw = [[POItableVIEwController alloc] init];    [self addChildVIEwController:_poitableVIEw];    _poitableVIEw.vIEw.frame = CGRectMake(0,self.vIEw.bounds.size.height / 2,self.vIEw.bounds.size.height);    UILongPressGestureRecognizer * tapGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(expandtableVIEw:)];    [_poitableVIEw.vIEw addGestureRecognizer:tapGesture];    [self.vIEw addSubvIEw:_poitableVIEw.vIEw];    [_poitableVIEw dIDMovetoParentVIEwController:self];}

这是我的动画功能:

- (voID) expandtableVIEw:(UITapGestureRecognizer *)sender{    NSLog(@"ExpandtableVIEw Animation");    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];    float cellHeight = [_poitableVIEw getHeightForIndexPath:indexPath];    NSLog(@"Cell height %f",cellHeight );    float navbarHeight = self.navigationController.navigationbar.frame.size.height;    [UIVIEw animateWithDuration:1.0                          delay:0.2                        options:0                     animations:^{                         if(_isstartUpposition)                         {                             NSLog(@"StartUp");                             _poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,_poitableVIEw.vIEw.frame.origin.y - ( _poitableVIEw.vIEw.frame.origin.y -  navbarHeight - 2 * cellHeight ),_poitableVIEw.vIEw.frame.size.wIDth,_poitableVIEw.vIEw.frame.size.height);                             _isMapExpanded = NO;                             _isstartUpposition = NO;                         }                         else if(_isMapExpanded)                         {                             NSLog(@"tableVIEw is Now being expanded");                             _poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,_poitableVIEw.vIEw.frame.size.height);                             _isMapExpanded = NO;                         }                     }                     completion:nil];}- (voID) expandMap:(UITapGestureRecognizer *)sender{    NSLog(@"ExpandMap Animation");    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];    float cellHeight = [_poitableVIEw getHeightForIndexPath:indexPath];    [UIVIEw animateWithDuration:1.0                          delay:0.2                        options:0                     animations:^{                         if(_isstartUpposition)                         {                             NSLog(@"StartUp");                             _poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,_poitableVIEw.vIEw.frame.origin.y + _poitableVIEw.vIEw.frame.origin.y - cellHeight,_poitableVIEw.vIEw.frame.size.height);                             _isMapExpanded = YES;                             _isstartUpposition = NO;                         }                         else if(!_isMapExpanded)                         {                             NSLog(@"Map is Now being expanded");                             _poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,_poitableVIEw.vIEw.frame.origin.y + 2 * _poitableVIEw.vIEw.frame.origin.y,_poitableVIEw.vIEw.frame.size.height);                             _isMapExpanded = YES;                         }                     }                     completion:nil];}

我只是找不到两者之间的比例所以它们可能总是一样的.在每个屏幕上.

编辑

这是我的地图展开

if(!_isMapExpanded)                 {                     NSLog(@"Map is Now being expanded");                  _poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,_poitableVIEw.vIEw.frame.origin.y,_shrankHeight);                     _isMapExpanded = YES;                     _mapVIEw.vIEw.frame = CGRectMake(_mapVIEw.vIEw.frame.origin.x,_mapVIEw.vIEw.frame.origin.y,_mapVIEw.vIEw.frame.size.wIDth,_expandedHeight);                 }

这是我的tablevIEw扩展:

if(_isMapExpanded)                 {                     NSLog(@"tableVIEw is Now being expanded");                     _poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,_expandedHeight);                     _mapVIEw.vIEw.frame = CGRectMake(_mapVIEw.vIEw.frame.origin.x,_shrankHeight);                     _isMapExpanded = NO;                 }

我现在拥有的是,当我的桌面视图要扩展时,它只会进入屏幕的一半而不是顶部.

解决方法
@property float shrankHeight;@property float expandedHeight;@property float normalHeight;- (voID) calculateHeights{    CGRect screenBounds = [[UIScreen mainScreen] bounds];    // If you're going to use landscape,use wIDth.    normalHeight = (screenBounds.height - 44) / 2.0; // Don't forget the navigation bar,though.    shrankHeight = normalHeight / 3.0;    expandedHeight = normalHeight * 5.0 / 3;}

计算出高度后,可以在动画块中使用它们.

例如,如果地图要扩展,您应该:

_poitableVIEw.vIEw.frame = CGRectMake(_poitableVIEw.vIEw.frame.origin.x,shrankHeight);

_mapVIEw.vIEw.frame = CGRectMake(_mapVIEw.vIEw.frame.origin.x,_mapVIEw.vIEw.frame.origin.y + 2 * _mapVIEw.vIEw.frame.origin.y,expandedHeight);

你可能需要改变他们的中心.

总结

以上是内存溢出为你收集整理的ios – 找不到调整两个视图大小的数学公式全部内容,希望文章能够帮你解决ios – 找不到调整两个视图大小的数学公式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1024427.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存