recherche

Maison  >  Questions et réponses  >  le corps du texte

ios - convertRect:view.frame toView:window x 异常翻倍?

    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    NSLog(@"window.f %@", NSStringFromCGRect(window.frame));
    CGRect newFrame = [view convertRect:view.frame toView:window]; 
    NSLog(@"原始:%@ 转换:%@", NSStringFromCGRect(view.frame), NSStringFromCGRect(newFrame));

window.f {{0, 0}, {320, 480}}
原始:{{85, 7}, {150, 30}} 转换:{{170, 34}, {150, 30}}

为什么 x 被翻倍了?
View 为灰色控件

如果将控件放到view 中

2016-03-07 02:39:25.662 微博2期[57203:938330] window.f {{0, 0}, {320,
480}} 2016-03-07 02:39:25.662 微博2期[57203:938330] 原始:{{20, 60}, {40,
20}} 转换:{{40, 184}, {40, 20}}

得到以上数据。。。184 - 64 正好 120,也就是说x * 2, y * 2 了

将控件添加到一个视图中,相对于视图转换(这个比较难说明白,简单说就是排除了各种bar的干扰)结果直接x y 都双倍了。。。

PHP中文网PHP中文网2887 Il y a quelques jours368

répondre à tous(2)je répondrai

  • ringa_lee

    ringa_lee2017-04-17 17:39:42

    Deux manières correctes d'écrire

    [view.superview convertRect:view.frame  toView:nil];
    [view           convertRect:view.bounds toView:window];
    

    L'appelant de convertRect a un malentendu. Ce devrait être la vue du cadre de référence du contrôle qui doit être convertie, pas elle-même.

    répondre
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:39:42

    [view convertRect:view.frame toView:window] -> Si [view convertRect:view.frame toView:nil]
    est remplacé par ceci, il n'y aura aucun problème avec la description du sujet.

    répondre
    0
  • Annulerrépondre