小编cdp*_*mer的帖子

如何在swift中将Int32值转换为CGFloat?

在这里我的代码.我正在传递两个值CGRectMake(..)并获得和错误.

let width = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).width
// return Int32 value

let height = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).height
// return Int32 value

myLayer?.frame = CGRectMake(0, 0, width, height)
// returns error: '`Int32`' not convertible to `CGFloat`
Run Code Online (Sandbox Code Playgroud)

如何转换Int32CGFloat不返回错误?

int32 cgfloat swift ios8.1

25
推荐指数
1
解决办法
3万
查看次数

无法验证https://rubygems.org/的SSL证书

我跑的时候收到这个错误bundle install:

Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely 
your system doesn't have the CA certificates needed for verification. For
information about OpenSSL certificates, see bit.ly/ruby-ssl. To connect without using 
SSL, edit your Gemfile sources and change 'https' to 'http'.
Run Code Online (Sandbox Code Playgroud)

然而,它只发生在我的一个项目中,似乎只发生在我身上.此外,我可以通过运行绕过它bundle update,在那里我没有得到那个错误,我可以在那之后起床.

项目中是否存在未被跟踪的东西(仅在我的机器上)我配置错误?

ruby git ssl ruby-on-rails github

13
推荐指数
3
解决办法
1万
查看次数

如何判断时间/日期是否为今天,红宝石?

我有一个解决方案,我想判断一下return_service_date是否是今天,该怎么做?

这是我的代码(rails):

if settlement.return_service_date && 
   settlement.return_service_date.to_s(:date) == Time.now.to_s(:date)
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

ruby ruby-on-rails

11
推荐指数
2
解决办法
3521
查看次数

在UICollectionView中将单元格对齐在中心(水平)

我第一次使用UICollectionView不知道如何做到这一点.我正在尝试为tvOS创建一个应用程序,并希望显示像airbnb tvos app这样的菜单.我以某种方式尝试实现该特定格式didUpdateFocusInContext但问题是关于第一次出现,因为第一次出现发生在默认点上,即0,0的集合视图导致混乱.继承了我迄今为止所做的工作.

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
  if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as? ShowCell {
    menuData = dataArray[indexPath.row] as! NSDictionary
    cell.configureCell(menuData.objectForKey("name") as! String)

    return cell
  }
  else {
    return ShowCell()
  }
}

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
  if let previousItem = context.previouslyFocusedView as? ShowCell {
    UIView.animateWithDuration(0.2, animations: { () -> Void in
      previousItem.showImg.frame.size = self.originalCellSize
    })
  }
  if let nextItem = context.nextFocusedView as? ShowCell {
    UIView.animateWithDuration(0.2, animations: { …
Run Code Online (Sandbox Code Playgroud)

center ios uicollectionview swift tvos

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

`allow_any_instance_of` mock在范围内不起作用

我的模拟仅在下面显示的前一个块中工作.这只是我对问题的快速而肮脏的表现.字面上,当我从前一个块移动线到does not quack断言时,它停止嘲笑:(

describe 'Ducks', type: :feature do
  before do
    ...
    allow_any_instance_of(Duck).to receive(:quack).and_return('bark!')
    visit animal_farm_path
  end

  context 'is an odd duck'
    it 'does not quack' do
      expect(Duck.new.quack).to eq('bark!')
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我想在这里,但它不起作用:

describe 'Ducks', type: :feature do
  before do
    ...
    visit animal_farm_path
  end

  context 'is an odd duck'
    it 'does not quack' do
      allow_any_instance_of(Duck).to receive(:quack).and_return('bark!')
      expect(Duck.new.quack).to eq('bark!')
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails

6
推荐指数
1
解决办法
4194
查看次数

Swift:在touchesBegan中使用switch语句

我想清理我touchesBegan(..)SKScene.我想做一个case语句而不是我的if .. else链.但是,我在实现时遇到错误,这表明我不知道如何在引擎盖下完成相同的操作.

代码之前:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        if self.nodeAtPoint(location) === playLabel {
            buildLevelSelect()
        } else if self.nodeAtPoint(location) === aboutLabel {
            createAboutView()
        } else if self.nodeAtPoint(location) === storeLabel {
            createStore()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

代码之后:点击后,某些标签点击工作,但其他一些引发Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode 0x0)错误:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        switch(self.nodeAtPoint(location)){ …
Run Code Online (Sandbox Code Playgroud)

switch-statement ios sprite-kit skscene swift

4
推荐指数
1
解决办法
638
查看次数