@@ -1808,7 +1808,8 @@ -(void)layoutSubviews
1808
1808
// 设置子视图的frame并还原
1809
1809
for (UIView *sbv in self.subviews )
1810
1810
{
1811
- CGPoint ptorigin = sbv.bounds .origin ;
1811
+ CGRect sbvOldBounds = sbv.bounds ;
1812
+ CGPoint sbvOldCenter = sbv.center ;
1812
1813
1813
1814
MyFrame *sbvmyFrame = sbv.myFrame ;
1814
1815
UIView *sbvsc = [self myCurrentSizeClassFrom: sbvmyFrame];
@@ -1833,22 +1834,54 @@ -(void)layoutSubviews
1833
1834
if ([sbv isKindOfClass: [MyBaseLayout class ]])
1834
1835
{
1835
1836
rc = _myRoundRectForLayout (sbvmyFrame.frame );
1837
+
1838
+
1839
+ CGRect sbvTempBounds = CGRectMake (sbvOldBounds.origin .x , sbvOldBounds.origin .y , rc.size .width , rc.size .height );
1840
+
1841
+ if (_myCGFloatErrorEqual (sbvTempBounds.size .width , sbvOldBounds.size .width , _myMLayoutSizeError))
1842
+ sbvTempBounds.size .width = sbvOldBounds.size .width ;
1843
+
1844
+ if (_myCGFloatErrorEqual (sbvTempBounds.size .height , sbvOldBounds.size .height , _myMLayoutSizeError))
1845
+ sbvTempBounds.size .height = sbvOldBounds.size .height ;
1846
+
1847
+
1848
+ if (_myCGFloatErrorNotEqual (sbvTempBounds.size .width , sbvOldBounds.size .width , _myMLayoutSizeError)||
1849
+ _myCGFloatErrorNotEqual (sbvTempBounds.size .height , sbvOldBounds.size .height , _myMLayoutSizeError))
1850
+ {
1851
+ sbv.bounds = sbvTempBounds;
1852
+ }
1853
+
1854
+ CGPoint sbvTempCenter = CGPointMake (rc.origin .x + sbv.layer .anchorPoint .x * sbvTempBounds.size .width , rc.origin .y + sbv.layer .anchorPoint .y * sbvTempBounds.size .height );
1855
+
1856
+ if (_myCGFloatErrorEqual (sbvTempCenter.x , sbvOldCenter.x , _myMLayoutSizeError))
1857
+ sbvTempCenter.x = sbvOldCenter.x ;
1858
+
1859
+ if (_myCGFloatErrorEqual (sbvTempCenter.y , sbvOldCenter.y , _myMLayoutSizeError))
1860
+ sbvTempCenter.y = sbvOldCenter.y ;
1861
+
1862
+
1863
+ if (_myCGFloatErrorNotEqual (sbvTempCenter.x , sbvOldCenter.x , _myMLayoutSizeError)||
1864
+ _myCGFloatErrorNotEqual (sbvTempCenter.y , sbvOldCenter.y , _myMLayoutSizeError))
1865
+ {
1866
+ sbv.center = sbvTempCenter;
1867
+ }
1868
+
1869
+
1836
1870
}
1837
1871
else
1838
1872
{
1839
1873
rc = _myRoundRect (sbvmyFrame.frame );
1840
- }
1841
-
1842
1874
1843
- sbv.center = CGPointMake (rc.origin .x + sbv.layer .anchorPoint .x * rc.size .width , rc.origin .y + sbv.layer .anchorPoint .y * rc.size .height );
1844
- sbv.bounds = CGRectMake (ptorigin.x , ptorigin.y , rc.size .width , rc.size .height );
1875
+ sbv.center = CGPointMake (rc.origin .x + sbv.layer .anchorPoint .x * rc.size .width , rc.origin .y + sbv.layer .anchorPoint .y * rc.size .height );
1876
+ sbv.bounds = CGRectMake (sbvOldBounds.origin .x , sbvOldBounds.origin .y , rc.size .width , rc.size .height );
1877
+
1878
+ }
1845
1879
1846
-
1847
1880
}
1848
1881
1849
1882
if (sbvsc.myVisibility == MyVisibility_Gone && !sbv.isHidden )
1850
1883
{
1851
- sbv.bounds = CGRectMake (ptorigin. x , ptorigin .y , 0 , 0 );
1884
+ sbv.bounds = CGRectMake (sbvOldBounds. origin . x , sbvOldBounds. origin .y , 0 , 0 );
1852
1885
}
1853
1886
1854
1887
if (sbvmyFrame.sizeClass .viewLayoutCompleteBlock != nil )
@@ -1869,8 +1902,8 @@ -(void)layoutSubviews
1869
1902
1870
1903
// 因为布局子视图的新老尺寸计算在上面有两种不同的方法,因此这里需要考虑两种计算的误差值,而这两种计算的误差值是不超过1/屏幕精度的。
1871
1904
// 因此我们认为当二者的值超过误差时我们才认为有尺寸变化。
1872
- BOOL isWidthAlter = fabs (newSelfSize.width - oldSelfSize.width ) > _myMLayoutSizeError;
1873
- BOOL isHeightAlter = fabs (newSelfSize.height - oldSelfSize.height ) > _myMLayoutSizeError;
1905
+ BOOL isWidthAlter = _myCGFloatErrorNotEqual (newSelfSize.width , oldSelfSize.width , _myMLayoutSizeError) ;
1906
+ BOOL isHeightAlter = _myCGFloatErrorNotEqual (newSelfSize.height , oldSelfSize.height , _myMLayoutSizeError) ;
1874
1907
1875
1908
// 如果父视图也是布局视图,并且自己隐藏则不调整自身的尺寸和位置。
1876
1909
BOOL isAdjustSelf = YES ;
@@ -3513,6 +3546,24 @@ -(NSString*)description
3513
3546
@end
3514
3547
3515
3548
3549
+ BOOL _myCGFloatErrorEqual (CGFloat f1, CGFloat f2, CGFloat error)
3550
+ {
3551
+ #if CGFLOAT_IS_DOUBLE == 1
3552
+ return fabs (f1 - f2) < error;
3553
+ #else
3554
+ return fabsf (f1 - f2) < error;
3555
+ #endif
3556
+ }
3557
+
3558
+ BOOL _myCGFloatErrorNotEqual (CGFloat f1, CGFloat f2, CGFloat error)
3559
+ {
3560
+ #if CGFLOAT_IS_DOUBLE == 1
3561
+ return fabs (f1 - f2) > error;
3562
+ #else
3563
+ return fabsf (f1 - f2) > error;
3564
+ #endif
3565
+ }
3566
+
3516
3567
BOOL _myCGFloatEqual (CGFloat f1, CGFloat f2)
3517
3568
{
3518
3569
#if CGFLOAT_IS_DOUBLE == 1
@@ -3590,7 +3641,7 @@ CGFloat _myRoundNumber(CGFloat f)
3590
3641
if (f == 0 || f == CGFLOAT_MAX || f == -CGFLOAT_MAX)
3591
3642
return f;
3592
3643
3593
- int fi = round (f);
3644
+ int fi = rint (f);
3594
3645
if (_myCGFloatEqual (f, fi))
3595
3646
return fi;
3596
3647
0 commit comments