swift3

Place AVPlayerViewController inside UIView

感情迁移 提交于 2019-12-23 12:28:52
问题 Currently I am having a dialogue view with four controls at the bottom. Each control is loading a different view inside the dialogue. One of these controls is setting an AVPlayer inside the dialogue view and is playing it. Unfortunately the AVPlayer itself comes without playback controls. The AVPlayerViewController how ever does have playback controls. Is it possible to place a AVPlayerViewController inside a UIView so that it does not get started as a new screen? I would like to place it

Convert a JSON string to Dictionary in Swift 3

牧云@^-^@ 提交于 2019-12-23 12:28:18
问题 as a coding exercise, I wrote a small program to take MySql data frm the web to the iPhone. On the server side. I wrote the php script to get the script to return the json data. On xcode I have [code] . . . let jsonString = try? JSONSerialization.jsonObject(with: data!, options: []) print(jsonString!) . . . [/code] In xcode console, I have this: [code] ( { Address = "1 Infinite Loop Cupertino, CA"; Latitude = "37.331741"; Longitude = "-122"; Name = Apple; } ) [/code] I have a function [code]

NSValue(CMTime: ) in swift 3?

旧时模样 提交于 2019-12-23 12:25:22
问题 i have this code var times = [NSValue]() for time in timePoints { times.append(NSValue(CMTime : time)) } i get an error that their is nothing called CMTime in swift 3 i can't really find any param for cm time.. 回答1: Check the reference of NSValue. init(time: CMTime) Use NSValue(time: time) . One more. If you want to convert [CMTime] to [NSValue] , you can write something like this: let times = timePoints.map(NSValue.init(time:)) 来源: https://stackoverflow.com/questions/38669061/nsvaluecmtime

What is equivalent of “dispatch_apply” in Swift 3?

不想你离开。 提交于 2019-12-23 11:49:17
问题 I have been searching for an equivalent of dispatch_apply in swift3. Help me please convert let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_apply(2, queue) { (index) in } 回答1: Do you still remember dispatch_apply() . Well, it's still there and got a new name. From now on you have to call concurrentPerform() change this dispatch_apply(2, queue) { (index) in } into DispatchQueue.concurrentPerform(iterations: 2) { print("\($0). concurrentPerform") } 来源: https:

How to recognise which image was touched

左心房为你撑大大i 提交于 2019-12-23 11:44:30
问题 I am developing an application which the user will be able to drag and drop items on a canvas and when he releases the image it is drawn on the canvas. This is my DragImage class which handle the touches: class DragImages: UIImageView { var originalPos : CGPoint! var dropTarget: UIView? override init (frame : CGRect){ super.init(frame: frame) } required init?(coder aDecoder : NSCoder){ super.init(coder : aDecoder) } override func touchesBegan(_ touches : Set<UITouch>,with event: UIEvent?){

Segmentation fault: 11 - Cross-reference to module

微笑、不失礼 提交于 2019-12-23 10:19:56
问题 I'm trying to resolve an Segmentation Fault with Cross-references to modules. Don't know how to make this work. Part of error below: 1. While reading from /Users/damiandudycz/Library/Developer/Xcode/DerivedData/Hypno-azmcjycezcoqnfauqcbgimvipjyj/Build/Intermediates/Hypno.build/Debug-iphonesimulator/Hypno.build/Objects-normal/x86_64/WorldObjectBasedAugmentedRealityObject~partial.swiftmodule 2. While deserializing 'WorldObjectBasedAugmentedRealityObject' (ClassDecl #12) 3. While deserializing

DispatchGroup: check how many “entered”

倖福魔咒の 提交于 2019-12-23 10:17:41
问题 I'm using Swift 3 DispatchGroup to wait until multiple async operations are finished (according to this answer which works perfect and as expected. Is there a way to check how many operations are entered already, like dispatchGroup.count or something like that? 回答1: NO, nothing. You need to balance your enter() and leave() by yourself without counting. DispatchGroup 回答2: You can see counts of enters to the group in debug description: OS_dispatch_group: group[0x60000221d950] = { xref = 3, ref

Issues scaling sprite width to screen width

天大地大妈咪最大 提交于 2019-12-23 10:06:45
问题 Practically I am trying to achieve not too different from what was done in this question (scale a sprite regardless of it's position on the screen till it fills the screen width). Please see my code below: if touch?.tapCount == 2 { self.view?.isUserInteractionEnabled = false mySprite?.sprite.anchorPoint = CGPoint(x: (mySprite?.sprite.position.x)! / self.size.width, y: (mySprite?.sprite.anchorPoint.y)!) let scaleSpriteAction = SKAction.scaleX(to: self.size.width / (mySprite?.sprite.size.width)

What is the shortest code to get surrounding coordinates?

六眼飞鱼酱① 提交于 2019-12-23 09:55:48
问题 I don't like my following implementation of surroundingPositions to get the x- and y-Coordinates surrounding a specific position, because in my opinion it is too long for the simple intent and it has a pyramid of doom structure. struct Position: CustomStringConvertible { let x, y: Int var surroundingPositions: [Position] { var surroundingPositions: [Position] = [] for x in (self.x - 1)...(self.x + 1) { for y in (self.y - 1)...(self.y + 1) { if !(x == self.x && y == self.y) {

CAKeyFrameAnimation not Linear for values greater than PI

我的未来我决定 提交于 2019-12-23 09:17:08
问题 I am having some trouble to understand why an animation isn't working like expected. What I am doing is this: Create a UIBezierPath with an arc to move a Label along this path and animate the paths stroke. //Start Point is -.pi /2 to let the Arc start at the top. //self.progress = Value between 0.0 and 1.0 let path : UIBezierPath = UIBezierPath.init(arcCenter: CGPoint.init(x: self.bounds.width * 0.5, y: self.bounds.height * 0.5), radius: self.bounds.width * 0.5, startAngle: -.pi / 2, endAngle