小编Rom*_*nko的帖子

AVPlayer videoGravity AVLayerVideoGravityResizeAspectFill不能正常工作Swift2.2

请帮我AVPlayer.我需要在iPhone旋转时调整视频大小(横向).这是我的代码:

var player: AVPlayer?

override func viewDidLoad() {
    super.viewDidLoad()

    // Load the video from the app bundle.
    let videoURL: NSURL = NSBundle.mainBundle().URLForResource("bg_animate", withExtension: "3gp")!

    player = AVPlayer(URL: videoURL)
    player?.actionAtItemEnd = .None
    player?.muted = true

    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    playerLayer.zPosition = -1
    playerLayer.frame = view.frame
    view.layer.addSublayer(playerLayer)
    player?.play()

    //loop video
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.loopVideo), name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
}
Run Code Online (Sandbox Code Playgroud)

但是字符串:

playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
Run Code Online (Sandbox Code Playgroud)

不起作用.

我还设置值AVLayerVideoGravityResizeAVLayerVideoGravityResizeAspect,但也有类似的结果...

swift

6
推荐指数
0
解决办法
1065
查看次数

更新型号Realm Swift

我是Realm的新手,请你帮助我.我创建了模型:

class UserModel: Object {

    dynamic var email = ""
    dynamic var facebook_id = ""
    dynamic var google_id = ""
    dynamic var id = 0
    dynamic var name = ""
    dynamic var photo = ""
    dynamic var someinfo = ""
    dynamic var twitter_id = "" 

}
Run Code Online (Sandbox Code Playgroud)

当我登录app时,我可以在UserProfileController上看到我的信息.我还有一个EditProfileController,我可以在其中更改有关我自己的一些信息.所以当我成功更改它时,我想更新我的Realm模型,并尝试这样做:

    let realm = try! Realm()

    try! realm.write {
        realm.create(UserModel.self, value: ["name": self.editEmail.text!, "email": self.editEmail.text!], update: true)
    }
Run Code Online (Sandbox Code Playgroud)

但不幸的是我看到了这样的信息:

''UserModel' does not have a primary key and can not be updated'
Run Code Online (Sandbox Code Playgroud)

如果我想同时更新一些房产怎么办?我可以用primaryKey做到这一点吗?或者......如何在没有primaryKey的情况下更新Realm模型?

realm ios swift

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

Apollo iOS:Command/bin/sh失败,退出代码为1 | 命令PhaseScriptExecution失败,出现非零退出代码

我按照Apollo的安装教程进行操作.而且我完全相信我按照安装教程中的描述完成了所有工作.但是,在项目构建期间,我收到了编译器错误,如:

TypeError:无法读取未定义的属性"length"

at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
at Object.runCommand (/usr/local/lib/node_modules/apollo- codegen/node_modules/yargs/lib/command.js:235:44)
at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
Run Code Online (Sandbox Code Playgroud)

命令/ bin/sh失败,退出代码为1

++ exec apollo-codegen生成--schema schema.json --output API.swift

TypeError:无法读取未定义的属性"length"

at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
at Object.runCommand (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/lib/command.js:235:44)
at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js …
Run Code Online (Sandbox Code Playgroud)

ios apollo swift apollo-client

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

传递#selector Swift 2.2中的Argument

我有一个方法:

func followUnfollow(followIcon: UIImageView, channelId: String) {
    let followUnfollow = followIcon
    let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.followIconTapped(_:)))
    followUnfollow.userInteractionEnabled = true
    followUnfollow.addGestureRecognizer(tapGestureRecognizer)
}
Run Code Online (Sandbox Code Playgroud)

而且我有一个方法:

func followIconTapped(sender: UITapGestureRecognizer) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

它的工作正常.但我需要传递channelIdfollowIconTapped()方法.

我试试这个:

func followUnfollow(followIcon: UIImageView, channelId: String) {
    ...
    let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.followIconTapped(_:channelId)))
    ...
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试抓住它:

func followIconTapped(sender: UITapGestureRecognizer, channelId: String) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

xCode说channelId永远不会使用.为什么?当我构建项目时,我没有任何问题.但是,如果我点击followIcon, app就会崩溃.

拜托,你可以给我建议如何在传递channelIdfollowIconTapped()

ios swift2

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

标签 统计

ios ×3

swift ×3

apollo ×1

apollo-client ×1

realm ×1

swift2 ×1