日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一个 bug / Masonry的引入

發布時間:2024/4/14 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一个 bug / Masonry的引入 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
支持iOS?6/6 Plus的時候碰到這樣一個問題: 塞在UITableViewCell里的UIPageControl居中設置失敗了,偏右 剛剛設置時下斷點查看(6Plus模擬器): <GrayPageControl: 0x7f96a535c350; baseClass = UIPageControl; frame = (179.5 241.75; 55 6); autoresize = W; layer = <CALayer: 0x7f96a535c4a0>> 運行后: <GrayPageControl: 0x7f96a535c350; baseClass = UIPageControl; frame = (179.333 241.75; 149 6); autoresize = W; layer = <CALayer: 0x7f96a535c4a0>> 好奇在什么時候被改變的,考慮搞個內存修改斷點,上lldb,聽從忠告檢測CALayer的frame改動而不是UIView的: (lldb) po pc
<GrayPageControl: 0x15fe26ca0; baseClass = UIPageControl; frame = (160 217.375; 55 6); autoresize = W; layer = <CALayer: 0x174c38500>>

(lldb) break set -F '-[CALayer setBounds:]' -c '$x0 == 0x174c38500'
Breakpoint 113: where = QuartzCore`-[CALayer setBounds:], address = 0x000000018a3eb93c 結果是 layoutSubviews:? #0 0x000000018a3eb93c in -[CALayer setBounds:] () #1 0x000000018a3ec684 in -[CALayer setFrame:] () #2 0x000000018aa9da3c in -[UIView(Geometry) setFrame:] () #3 0x000000018aaba7b4 in -[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:] () #4 0x000000018618cfc8 in __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke () #5 0x000000018618ce6c in -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] () #6 0x000000018aaa9f58 in -[UIView(Geometry) resizeSubviewsWithOldSize:] () #7 0x000000018aa9daf4 in -[UIView(Geometry) setFrame:] () #8 0x000000018ab7b9d4 in -[UITableViewCellContentView setFrame:] () #9 0x000000018abe442c in __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke () #10 0x000000018aab24c8 in +[UIView(Animation) performWithoutAnimation:] () #11 0x000000018abe3b0c in -[UITableView _configureCellForDisplay:forIndexPath:] () #12 0x000000018ad9b4d8 in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] () #13 0x000000018ad9006c in -[UITableView _updateVisibleCellsNow:isRecursive:] () #14 0x000000018ab84c44 in -[UITableView layoutSubviews] () #15 0x000000018aaa14a4 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] () #16 0x000000018a3f57a8 in -[CALayer layoutSublayers] () #17 0x000000018a3f0378 in CA::Layer::layout_if_needed(CA::Transaction*) () #18 0x000000018a3f021c in CA::Layer::layout_and_display_if_needed(CA::Transaction*) () #19 0x000000018a3efa14 in CA::Context::commit_transaction(CA::Transaction*) () #20 0x000000018a3ef798 in CA::Transaction::commit() () #21 0x000000018a3e91c8 in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) () #22 0x000000018624ed98 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ () #23 0x000000018624bd24 in __CFRunLoopDoObservers () #24 0x000000018624c104 in __CFRunLoopRun () #25 0x00000001861791f4 in CFRunLoopRunSpecific () #26 0x000000018f59b6fc in GSEventRunModal () #27 0x000000018ab0a10c in UIApplicationMain () #28 0x0000000100029ce0 in main

?

看一下賦值過程: (lldb) po $x0
<CALayer:0x174c38500; position = CGPoint (215 220.375); bounds = CGRect (0 0; 55 6); delegate = <GrayPageControl: 0x15fe26ca0; baseClass = UIPageControl; frame = (187.5 217.375; 55 6); autoresize = W; layer = <CALayer: 0x174c38500>>; sublayers = (<CALayer: 0x170a3fd40>, <CALayer: 0x1704250a0>, <CALayer: 0x174c38200>, <CALayer: 0x174c38080>); opaque = YES; allowsGroupOpacity = YES; > (lldb) finish (lldb) po 0x174c38500 <CALayer:0x174c38500; position = CGPoint (215 220.375); bounds = CGRect (0 0; 110 6); delegate = <GrayPageControl: 0x15fe26ca0; baseClass = UIPageControl; frame = (160 217.375; 110 6); autoresize = W; layer = <CALayer: 0x174c38500>>; sublayers = (<CALayer: 0x170a3fd40>, <CALayer: 0x1704250a0>, <CALayer: 0x174c38200>, <CALayer: 0x174c38080>); opaque = YES; allowsGroupOpacity = YES; > 這里借了臺iPhone 6/iOS8, cpu是ARM64?所以得參考下面link里bcattle的補充回答,寄存器是$x0, iphone?5/iOS7 上用$r0 但是居然值沒變化。模擬器上沒成功。另外同樣是layoutSubviews 前者是UITableView的,后者是UITableViewCell調用的。 http://stackoverflow.com/questions/13976219/how-do-i-set-an-lldb-watchpoint-on-a-property-of-self-view 好奇滿足了,然后想辦法解決。so上搜索PageControl?UITableViewCell layoutSubViews/center?等等,沒有看到相關討論。某天學了一點AutoLayout趕緊過來寫一行: 1 [pc setTranslatesAutoresizingMaskIntoConstraints:NO]; 2 [cell.contentView addConstraints:[NSLayoutConstraint 3 constraintsWithVisualFormat:@"H:|-0-[pc]-0-|” 4 options:0 5 metrics:nil 6 views:NSDictionaryOfVariableBindings(pc)]]; 7 8 [cell.contentView addConstraints:[NSLayoutConstraint 9 constraintsWithVisualFormat:[NSString stringWithFormat: @"V:|-%f-[pc]-11-|", CGRectGetHeight(scroll.frame)-11-6] 10 options:0 11 metrics:nil 12 views:NSDictionaryOfVariableBindings(pc)]];

?

不賣關子,成功了。于是結論出來了,AutoLayout升級為必修。Masonry,我來了。

1 [pc mas_makeConstraints:^(MASConstraintMaker * make){ 2 make.bottom.equalTo(cell.contentView.mas_bottom).with.offset(-6); 3 make.centerX.equalTo(cell.contentView.mas_centerX); 4 }];

?

尾聲:storyboard的預覽功能+sizeClass會不會比傳統的手碼代碼快一點呢? 2015.03.30

轉載于:https://www.cnblogs.com/kurk/p/bug_introduce_masonry.html

總結

以上是生活随笔為你收集整理的一个 bug / Masonry的引入的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。