我正在尝试创建一个相机应用程序,它或多或少会像默认的相机应用程序.目前对我不起作用的东西是重点关注.我希望相机能够对焦并在触摸点上做任何事情,就像真正的相机应用程序一样.
这是我的viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
// Session
_session = [[AVCaptureSession alloc] init];
_session.sessionPreset = AVCaptureSessionPresetPhoto;
// Input
_videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
_videoInput = [AVCaptureDeviceInput deviceInputWithDevice:_videoDevice error:nil];
// Output
_frameOutput = [[AVCaptureVideoDataOutput alloc] init];
_frameOutput.videoSettings = [NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey];
[_frameOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
[_session addInput:_videoInput];
[_session addOutput:_frameOutput];
[_session startRunning];
};
Run Code Online (Sandbox Code Playgroud)
这里的方法应该让我的相机专注于点击.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = obj;
CGPoint touchPoint = [touch locationInView:touch.view];
focusLayer.frame = CGRectMake((touchPoint.x-25), (touchPoint.y-25), 50, 50);
if ([_videoDevice isFocusPointOfInterestSupported]) …
Run Code Online (Sandbox Code Playgroud) 我是Swift和SpriteKit的新手.很多SpriteKit动作的样本都在Objective C中,我无法在Swift中映射,也无法工作.
如果运行SKAction,并且在SKAction完成后想要做其他事情,我如何在Swift中做到这一点?
spaceMan.runAction(spaceManDeathAnimation, completion: {
println("red box has faded out")
})
Run Code Online (Sandbox Code Playgroud)
任何想法将不胜感激.
编辑:
for i in 0...29 {
textures.append(SKTexture(imageNamed: "spaceManDeath_\(i)"))
}
spaceManDeathAnimation = SKAction.repeatActionForever(SKAction.animateWithTextures(textures, timePerFrame: 0.15625))
Run Code Online (Sandbox Code Playgroud) 我正在尝试复制iPhone Camera应用程序的默认快门动画.
也许有人试过这样做并有一些提示要分享?
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;
// Configure the apperence of the circle
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor whiteColor].CGColor;
circle.lineWidth = 1;
// Add to parent layer
[[background layer] addSublayer:circle];
Run Code Online (Sandbox Code Playgroud)
我画了一个圆圈并将其添加为子图层.我不明白的是如何使圆线虚线?我在上面添加了我的圈子代码.
我有一个功能:
func runRockRotation(rockSprite: SKSpriteNode){
startRockRotationAnimation(rockSprite, isRock: true)
}
Run Code Online (Sandbox Code Playgroud)
当我这样称呼时:
runRockRotation(rock)
Run Code Online (Sandbox Code Playgroud)
它工作,但我似乎无法将其放入NSTimer选择器.
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "runRockRotation:", userInfo: rock, repeats: false)
Run Code Online (Sandbox Code Playgroud)
阅读了很多论坛,试过这个:
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "runRockRotation()", userInfo: rock, repeats: false)
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "runRockRotation(_)", userInfo: rock, repeats: false)
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "runRockRotation", userInfo: rock, repeats: false)
Run Code Online (Sandbox Code Playgroud)
此外,尝试没有摇滚,使用零,但似乎没有任何工作.
每次我得到:
2015-04-10 15:49:03.830 Meh[1640:218030] -[__NSCFTimer runAction:completion:]: unrecognized selector sent to instance 0x174166840
2015-04-10 15:49:03.832 Meh[1640:218030] *** Terminating app due …
Run Code Online (Sandbox Code Playgroud) 当我尝试构建我的项目时,我遇到了以下问题.
ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
在最新的Xcode更新之前,我通过CocoaPods使用OpenSSL就好了.在最新的OS和Xcode更新之后,我似乎无法构建OpenSSL.
任何想法如何解决这个问题?在Xcode 7上一切正常.
任何人都可以建议如何解决这个NSCollectionView
问题?从Swift 3转换为Swift 4并且魔术开始发生:)
码:
let item = NSNib(nibNamed: NSNib.Name(rawValue: "MACollectionViewItem"), bundle: nil)
collectionView.register(item, forItemWithIdentifier: "CollectionViewItem")
Run Code Online (Sandbox Code Playgroud)
第二行错误:
无法
register
使用类型的参数列表调用' ''(NSNib?, forItemWithIdentifier: String)'
ios ×4
swift ×3
camera ×2
avfoundation ×1
completion ×1
handler ×1
line ×1
macos ×1
nstimer ×1
objective-c ×1
openssl ×1
selector ×1
skaction ×1
sprite-kit ×1
swift3 ×1
swift4 ×1
xcode ×1
xcode8 ×1