小编Jus*_*ter的帖子

如何设置CG_CONTEXT_SHOW_BACKTRACE环境变量?

在我看来,我有三个按钮.在viewDidLoad()中设置cornerRadus之后:button.layer.cornerRadius = 20我在日志中收到以下错误消息:

 <Error>: CGContextSaveGState: invalid context 0x0. 
If you want to see the backtrace, please set 
CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Run Code Online (Sandbox Code Playgroud)

问题:

  • 如何设置CG_CONTEXT_SHOW_BACKTRACE环境变量?
  • 或者我该如何修复此警告?

好的,我现在从消息中回溯了.这对我没有任何意义.一些帮助请...

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 …
Run Code Online (Sandbox Code Playgroud)

xcode core-graphics ios swift

88
推荐指数
3
解决办法
6万
查看次数

使用Typescript和React.Konva指定onClick事件类型

我试图摆脱我的tslint错误,Type declaration of 'any' loses type-safety.但我正在努力弄清楚事件的正确类型.

我正在尝试将Lynda" 构建和部署全栈反应应用程序 ",同时尝试将其转换为Typescript.

以下是导致此问题的具体行:

onClick={(event: any) => {
 makeMove(ownMark, event.target.index)
}}
Run Code Online (Sandbox Code Playgroud)

我试图将事件声明为几种不同的类型,例如React.MouseEvent<HTMLElement>,加上HTMLElement上的一些其他子类型,但没有成功,因为target.index不是我能提出的任何类型的属性.我可以从检查器看到currentTarget是Konva.Text并且索引设置为0但不确定这对我有帮助,因为我无法将类型设置为Konva.Text,这对我来说是有意义的,但这也不起作用.

反应Konva事件目标索引

这是我完整的React功能组件:

export const Squares = ({units, coordinates, gameState, win, gameOver, yourTurn, ownMark, move}: SquaresProps) => {
  let squares = coordinates.map( (position: number, index: number) => { 
    let makeMove = move
    let mark = gameState[index] !== 'z' ? gameState[index] : false
    let fill = 'black'

    // when someone wins you want the square to turn …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs konvajs

44
推荐指数
7
解决办法
5万
查看次数

接到两个电话后,SKAction playSoundFileNamed不起作用

我试图弄清楚为什么playSoundFileNamed在接到两个连续的电话后无效.实际上它只在收到第一个电话后才有效.再现步骤是:

  1. 开始游戏
  2. 等待电话并转到后台
  3. 电话已完成(被来电者拒绝或中断)
  4. 回到前台

在此之后,播放来自touchesBegan的声音仍然有效.

当我重复上面的步骤(跳过第一步)时,touchesBegan的机制停止工作.不确定为什么会发生这种情况......以下是可以产生描述行为的代码:

@interface GameScene()

@property (nonatomic, strong) SKAction *sound;
@end

@implementation GameScene

-(void)didMoveToView:(SKView *)view {
    self.sound = [SKAction playSoundFileNamed:@"sound1.wav" waitForCompletion:NO];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    [self runAction:self.sound];
}
@end
Run Code Online (Sandbox Code Playgroud)

我知道在SO上有一些与此相关的问题,但是给出的答案与解决方法有关.我对解决方法不感兴趣,但为什么会发生这种情况呢?它与AVAudioSession有什么关系吗?(可能不是)我知道我可以使用AVAudioPlayer作为一种解决方法,但仍然不确定播放大量简单短音的效果是多少......

audio objective-c ios sprite-kit skaction

11
推荐指数
1
解决办法
437
查看次数

Swift 2:AVAssetReader和NSInputStream音频图

我试图转换Bob McCune的Learning AVFoundation书中的一个例子,并使用AVAssetReader和NSInputStream来解决一些问题.图形应该是纯正弦波,但值似乎以某种方式反映在X轴上.

我已经尝试过每次迭代的字节交换,我都能想到并且没有用.

Playground在这里发布到github:https: //github.com/justinlevi/AVAssetReader

//: Playground - noun: a place where people can play

import UIKit
import AVFoundation
import XCPlayground

func plotArrayInPlayground<T>(arrayToPlot:Array<T>, title:String) {
  for currentValue in arrayToPlot {
    XCPCaptureValue(title, value: currentValue)
  }
}

class SSSampleDataFilter {
  var sampleData:NSData?

  init(data:NSData) {
    sampleData = data
  }

  func filteredSamplesForSize(size:CGSize) -> [Int]{
    var filterSamples = [UInt16]()

    if let sampleData = sampleData {
      let sampleCount = sampleData.length
      let binSize = CGFloat(sampleCount) / size.width

      let stream = NSInputStream(data: sampleData)
      stream.open()

      var …
Run Code Online (Sandbox Code Playgroud)

avfoundation nsinputstream ios avassetreader swift2

7
推荐指数
1
解决办法
1622
查看次数