小编use*_*037的帖子

AVAssetTrack preferredTransform始终返回格局

我有应用程序记录视频.

要处理电话轮换,我有以下代码:

    // called on phone rotation
    AVCaptureConnection *previewLayerConnection = [[self previewLayer] connection];
    if ([previewLayerConnection isVideoOrientationSupported]) {
        [previewLayerConnection setVideoOrientation:[self getVideoOrientation]];
    }
Run Code Online (Sandbox Code Playgroud)

和getVideoOrientation函数:

- (AVCaptureVideoOrientation) getVideoOrientation {
    UIInterfaceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    AVCaptureVideoOrientation newOrientation = AVCaptureVideoOrientationPortrait;
    switch (deviceOrientation) {
        case UIInterfaceOrientationPortrait:
            NSLog(@"UIInterfaceOrientationPortrait");
            newOrientation = AVCaptureVideoOrientationPortrait;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            NSLog(@"UIInterfaceOrientationLandscapeRight");
            newOrientation = AVCaptureVideoOrientationLandscapeLeft;
            break;
        case UIInterfaceOrientationLandscapeRight:
            NSLog(@"UIInterfaceOrientationLandscapeLeft");
            newOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        default:
            NSLog(@"default");
            newOrientation = AVCaptureVideoOrientationPortrait;
            break;
    }

    return newOrientation;
}
Run Code Online (Sandbox Code Playgroud)

应用程序的这一部分正常工作(我在任何设备方向上都可以看到视频).但是当我尝试制作缩略图(或播放视频)时,我遇到了问题.

正如我在其他问题中所读到的,我为每首曲目做了以下事情:

        AVAssetTrack* videoTrack    = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
        CGAffineTransform txf …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios

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

Ruby On Rails设计移动Api

我正在构建基于Devise的移动api.

只要我需要json响应,我就实现了自定义SessionController和RegistrationController:

我的routes.rb看起来像:

devise_for(:users, :controllers => { :sessions => "api/sessions", :registrations => "api/registration"})
Run Code Online (Sandbox Code Playgroud)

AFAIK,自从Devise上次更新auth_token后不再使用(3.1.0.rc下的CHANGELOG.md).

这是我的注册控制器:

class Api::RegistrationController < Devise::RegistrationsController
  respond_to :json
  skip_before_filter :verify_authenticity_token

  def create
    user = User.new(params[:user])
    if user.save
      render :json=> {:auth_token=>user.authentication_token, :email=>user.email}, :status=>201
      #render :json=> {:success=>true}, :status=>201
      return
    else
      warden.custom_failure!
      render :json=> user.errors, :status=>422
    end
  end


  protected

  def invalid_login_attempt
    render :json=> {:success=>false, :message=>"Error with your login or password"}, :status=>401
  end
end
Run Code Online (Sandbox Code Playgroud)

和会话控制器:

class Api::SessionsController < Devise::SessionsController
  prepend_before_filter :require_no_authentication, :only => [:create ]
  before_filter :ensure_params_exist

  respond_to :json
  skip_before_filter :verify_authenticity_token …
Run Code Online (Sandbox Code Playgroud)

json ruby-on-rails devise ruby-on-rails-3

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

Elasticsearch query_string完全匹配

我有一个包含field有价值视频的索引1.flv.如果我执行以下查询:

"query": {
    "query_string": {
        "query": "2.flv"
    }
}
Run Code Online (Sandbox Code Playgroud)

查询仍然返回1.flv的所有记录.

谁能指出我正确的解决方案?

以下是为1.flv返回的示例数据(如您所见,没有包含2.flv!)

  "hits" : {
    "total" : 8,
    "max_score" : 0.625,
    "hits" : [ {
      "_index" : "videos",
      "_type" : "comment",
      "_id" : "_meta",
      "_score" : 0.625,
      "fields" : {
        "video" : "1.flv",
        "body" : "Really?"
      }
    }, {
      "_index" : "videos",
      "_type" : "comment",
      "_id" : "0fYsYOTHT7O-7P6CVi7l3w",
      "_score" : 0.625,
      "fields" : {
        "video" : "1.flv",
        "body" : "fadsfasfas"
      }
    }, {
      "_index" : "videos", …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

5
推荐指数
1
解决办法
5555
查看次数

使用 XIB 实例化视图

我通过以下指南创建了一个 xib(如何创建自定义 iOS 视图类并实例化它的多个副本(在 IB 中)?)但我有一个问题:

如何从代码实例化 if ?

那么我应该在 viewDidLoad 中写什么而不是

self.myView = [[MyView alloc] initWithFrame:self.view.bounds];
Run Code Online (Sandbox Code Playgroud)

我知道如何用故事板实例化它,但我不知道如何从代码中做到这一点。谢谢!

objective-c ios

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

Chrome 扩展全局变量

我已经使用清单版本 2 查看了 Chrome 扩展上的其他全局变量问题,但一无所获。

假设我有 2 个文件:

// content.js

var myVariable = myVariable(someDiv);
var myVarWithGlobe = VarWithGlobe.fromVariable(myVariable);
Run Code Online (Sandbox Code Playgroud)

// VarWithGlobe.js

var withGlobe = withGlobe || { };

withGlobe.WithGlobe = (function(global) {
    var myLocalVar = global.myVariable;
....

WithGlobe.fromVariable = WithGlobe;
Run Code Online (Sandbox Code Playgroud)

它们都被添加到web_accessible_resources, content_scripts但我无法访问第二个文件中的 global.myVariable 因为它是未定义的。

如果我不允许更改 VarWithGlobe.js,我如何获得它?

javascript google-chrome google-chrome-extension

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

NavigationController中的UIScrollView忽略顶部布局指南

我已经看到了关于自定义转换的类似问题(iOS7自定义ViewController转换和顶部布局指南导航控制器顶部布局指南不满足于自定义转换),但即使定期推送我也有问题.我正在使用最新的Xcode(版本5.1.1(5B1008)).

这是我的故事板: 故事板 第3个VC出现问题

这是第三个VC设置: 在此输入图像描述

我的第三个控制器的布局如下:

UIView
 UIScrollView
  InnerUIView
    Other views
Run Code Online (Sandbox Code Playgroud)

我尝试了两种不同的方法来创建布局:

忽略顶部布局指南(由于导航条,y = 64)

我将scrollview的顶部固定到容器(忽略topLayoutGuide),手动设置内部视图的高度并将其顶部固定为scrollView.它给了我以下结果: 在此输入图像描述

看起来很好,但为什么我需要顶部布局指南呢?

使用topLayout指南

ScrollView的顶部固定在topLayoutGuide上. 在此输入图像描述

如您所见,顶部按钮向下移动,视图看起来很奇怪.

创建此类布局的正确方法是什么?

uiscrollview ios autolayout

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

iOS Autolayout用于滚动视图和粘性页脚

假设我的布局如下图所示: 在此输入图像描述 根视图 - 是viewController的视图.我想要我的页脚文本

  • 如果内容适合一个屏幕(主要文字很小),则粘贴到屏幕底部
  • 在其他情况下,从主要文本15pt到屏幕底部15tt

我明白,我可以计算主文本高度并将其与当前屏幕大小进行比较,但我想找到另一种方式(理想情况下只有约束).

可能吗?

ios autolayout ios-autolayout

2
推荐指数
1
解决办法
1292
查看次数

如何在没有内容安全政策错误的内容脚本中使用Google +1?

我正在尝试使用+1 google api构建chrome扩展程序.

我的manifest.json看起来像:

"manifest_version": 2,
"content_security_policy": "script-src 'self' https://apis.google.com; object-src 'self'",
...
"matches": ["http://demosite.com/*"],
"js": ["js/jquery.js","js/social/plusone.js"]    
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我将apis.google.com列入白名单.

我的plusone.js看起来像:

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://apis.google.com/js/plusone.js";
head.appendChild(script);

$('li.subscription').before('<g:plusone></g:plusone>');
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我只是从白名单网站注入脚本标记.

不幸的是,当我加载页面时出现错误:

拒绝加载脚本apis.google.com/ / scs/apps-static / /js/k=oz.gapi.ru.Fqrb4MMzOT8.O/m...sv=1/d=1/ed=1/am=IQ /rs=AItRSTNEKbnLkdtNZVz4hKH7VV4tY98scw/cb=gapi.loaded_0'因为它违反了以下内容安全策略指令:"script-src'self'".

这里所有类似的问题都说我应该使用content_security_policy将网站列入白名单,但我已经完成了,你可以看到.有什么想法有什么不对吗?

javascript google-chrome google-chrome-extension google-plus-one google-plus

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