Saya memiliki tiga tombol dalam pandangan saya. Setelah mengatur cornerRadus di viewDidLoad (): button.layer.cornerRadius = 20
Saya mendapatkan pesan kesalahan berikut di log:
<Error>: CGContextSaveGState: invalid context 0x0.
If you want to see the backtrace, please set
CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Pertanyaan:
Bagaimana cara mengatur variabel lingkungan CG_CONTEXT_SHOW_BACKTRACE?- Atau bagaimana cara memperbaiki peringatan ini?
Oke, sekarang saya sudah menelusuri kembali pesannya. Itu tidak masuk akal bagiku. Tolong bantu ...
Aug 7 14:27:00 <Error>: CGContextSaveGState: invalid context 0x0. Backtrace:
<-[UIStatusBarItemView updateContentsAndWidth]+33>
<-[UIStatusBarItemView initWithItem:data:actions:style:]+477>
<+[UIStatusBarItemView createViewForItem:withData:actions:foregroundStyle:]+134>
<-[UIStatusBarLayoutManager _createViewForItem:withData:actions:]+163>
<-[UIStatusBarLayoutManager _prepareEnabledItemType:withEnabledItems:withData:actions:itemAppearing:itemDisappearing:]+36
<-[UIStatusBarLayoutManager prepareEnabledItems:withData:actions:]+92>
<-[UIStatusBarForegroundView _setStatusBarData:actions:animated:]+797>
<-[UIStatusBarForegroundView setStatusBarData:actions:animated:]+332>
<__51-[UIStatusBar _prepareToSetStyle:animation:forced:]_block_invoke+360>
<+[UIView(Animation) performWithoutAnimation:]+65>
<-[UIStatusBar _prepareToSetStyle:animation:forced:]+866>
<-[UIStatusBar _requestStyleAttributes:animationParameters:forced:]+391>
<-[UIStatusBar requestStyle:animationParameters:forced:]+437>
<-[UIStatusBar requestStyle:animated:forced:]+90>
<-[UIStatusBar _evaluateServerRegistration]+250>
<__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke+590>
<-[UIView(Hierarchy) _postMovedFromSuperview:]+544>
<-[UIView(Internal) _addSubview:positioned:relativeTo:]+1967>
<-[UIStatusBarWindow setStatusBar:]+288>
<-[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:]+340>
<-[UIApplication _runWithMainScene:transitionContext:completion:]+950>
<-[UIApplication workspaceDidEndTransaction:]+188>
<-[FBSSerialQueue _performNext]+192>
<-[FBSSerialQueue _performNextFromRunLoopSource]+45>
<__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+17>
<__CFRunLoopDoSources0+556>
<__CFRunLoopRun+867>
<CFRunLoopRunSpecific+488>
<-[UIApplication _run]+402>
<UIApplicationMain+171>
<main+117>
Aug 7 14:27:00 <Error>: CGContextTranslateCTM: invalid context 0x0. Backtrace:
<-[UIStatusBarItemView updateContentsAndWidth]+33>
<-[UIStatusBarItemView initWithItem:data:actions:style:]+477>
<+[UIStatusBarItemView createViewForItem:withData:actions:foregroundStyle:]+134>
<-[UIStatusBarLayoutManager _createViewForItem:withData:actions:]+163>
<-[UIStatusBarLayoutManager _prepareEnabledItemType:withEnabledItems:withData:actions:itemAppearing:itemDisappearing:]+36
<-[UIStatusBarLayoutManager prepareEnabledItems:withData:actions:]+92>
<-[UIStatusBarForegroundView _setStatusBarData:actions:animated:]+797>
<-[UIStatusBarForegroundView setStatusBarData:actions:animated:]+332>
<__51-[UIStatusBar _prepareToSetStyle:animation:forced:]_block_invoke+360>
<+[UIView(Animation) performWithoutAnimation:]+65>
<-[UIStatusBar _prepareToSetStyle:animation:forced:]+866>
<-[UIStatusBar _requestStyleAttributes:animationParameters:forced:]+391>
<-[UIStatusBar requestStyle:animationParameters:forced:]+437>
<-[UIStatusBar requestStyle:animated:forced:]+90>
<-[UIStatusBar _evaluateServerRegistration]+250>
<__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke+590>
<-[UIView(Hierarchy) _postMovedFromSuperview:]+544>
<-[UIView(Internal) _addSubview:positioned:relativeTo:]+1967>
<-[UIStatusBarWindow setStatusBar:]+288>
<-[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:]+340>
<-[UIApplication _runWithMainScene:transitionContext:completion:]+950>
<-[UIApplication workspaceDidEndTransaction:]+188>
<-[FBSSerialQueue _performNext]+192>
<-[FBSSerialQueue _performNextFromRunLoopSource]+45>
<__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+17>
<__CFRunLoopDoSources0+556>
<__CFRunLoopRun+867>
<CFRunLoopRunSpecific+488>
<-[UIApplication _run]+402>
<UIApplicationMain+171>
<main+117>
Aug 7 14:27:00 <Error>: CGContextRestoreGState: invalid context 0x0. Backtrace:
<-[UIStatusBarItemView updateContentsAndWidth]+33>
<-[UIStatusBarItemView initWithItem:data:actions:style:]+477>
<+[UIStatusBarItemView createViewForItem:withData:actions:foregroundStyle:]+134>
<-[UIStatusBarLayoutManager _createViewForItem:withData:actions:]+163>
<-[UIStatusBarLayoutManager _prepareEnabledItemType:withEnabledItems:withData:actions:itemAppearing:itemDisappearing:]+36
<-[UIStatusBarLayoutManager prepareEnabledItems:withData:actions:]+92>
<-[UIStatusBarForegroundView _setStatusBarData:actions:animated:]+797>
<-[UIStatusBarForegroundView setStatusBarData:actions:animated:]+332>
<__51-[UIStatusBar _prepareToSetStyle:animation:forced:]_block_invoke+360>
<+[UIView(Animation) performWithoutAnimation:]+65>
<-[UIStatusBar _prepareToSetStyle:animation:forced:]+866>
<-[UIStatusBar _requestStyleAttributes:animationParameters:forced:]+391>
<-[UIStatusBar requestStyle:animationParameters:forced:]+437>
<-[UIStatusBar requestStyle:animated:forced:]+90>
<-[UIStatusBar _evaluateServerRegistration]+250>
<__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke+590>
<-[UIView(Hierarchy) _postMovedFromSuperview:]+544>
<-[UIView(Internal) _addSubview:positioned:relativeTo:]+1967>
<-[UIStatusBarWindow setStatusBar:]+288>
<-[UIApplication _createStatusBarWithRequestedStyle:orientation:hidden:]+340>
<-[UIApplication _runWithMainScene:transitionContext:completion:]+950>
<-[UIApplication workspaceDidEndTransaction:]+188>
<-[FBSSerialQueue _performNext]+192>
<-[FBSSerialQueue _performNextFromRunLoopSource]+45>
<__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+17>
<__CFRunLoopDoSources0+556>
<__CFRunLoopRun+867>
<CFRunLoopRunSpecific+488>
<-[UIApplication _run]+402>
<UIApplicationMain+171>
<main+117>
ios
xcode
swift
core-graphics
mercusuar 16
sumber
sumber
Jawaban:
Ini bug di 9b5:
https://forums.developer.apple.com/thread/13683
Ajukan RADAR dengan Apple.
sumber
iOS 9.2
danXcode 7.2
Anda dapat mengatur variabel lingkungan melalui menu ini: Produk -> Skema -> Edit Skema. Di bawah item "Jalankan", cari tab "Argumen", Anda akan melihat "Variabel Lingkungan" di tab, Tambah
CG_CONTEXT_SHOW_BACKTRACE
dan setel nilainya ke YA.sumber
Masalah ini terjadi dengan Xcode 7. Dalam kasus saya, saya menghapus
UIViewControllerBasedStatusBarAppearance
dariInfo.plist
dan masalah terpecahkan! Lihat jawabannya di postingan ini :sumber
UIViewControllerBasedStatusBarAppearance
hanya karena mereka membutuhkannya, tetapi ternyata saya salah karena jawaban ini memiliki 19Di Xcode 7:
Dalam kasus Anda masih ingin status bar tersembunyi, hanya mengubah
UIViewControllerBasedStatusBarAppearance
dalamInfo.plist
file keView controller-based status bar appearance
. Jangan lupa untuk mengaturnyaNO
sumber
UIViewControllerBaseStatusBarAppearance
danView controller-based status bar appearance
hal yang sama diInfo.plist
. Salah satunya adalah nilai kunci dan yang lainnya adalah teks yang berhadapan dengan pengguna.