我找到了一个类似的问题,但它没有回答我的问题.我有一个UIButton从屏幕底部到顶部的动画.我希望能够在移动时使用按钮.现在,该按钮只能在动画结束且按钮不再动画时使用.另外,我听说我可能需要使用一些叫做的东西NSTimer?
class ViewController: UIViewController {
@IBAction func button2(sender: UIButton) {
button.hidden = false
button.center = CGPointMake(126, 380);
UIView.animateKeyframesWithDuration(3, delay: 0, options: .AllowUserInteraction,
animations: { () -> Void in
self.button.center = CGPointMake(126, 130 )
}) { (_) -> Void in
}
}
@IBOutlet var label: UILabel!
@IBOutlet var button: UIButton!
@IBAction func button1(sender: UIButton) {
button.hidden = true
label.hidden = false
}
override func viewDidLoad() {
super.viewDidLoad()
button.hidden = true
label.hidden = true
}
}
Run Code Online (Sandbox Code Playgroud) 我试图用SKShapeNode纹理旋转,但它不起作用。基本上,我有一个带有纹理的圆圈,我试图使用与以下操作相同的方式使其旋转SKSpriteNode:
let spin = SKAction.rotateByAngle(CGFloat(M_PI/4.0), duration: 1)
Run Code Online (Sandbox Code Playgroud)
问题是圆圈在旋转,但纹理没有旋转。我可以使用以下代码检查这一点:
let wait = SKAction.waitForDuration(0.5)
let block = SKAction.runBlock({
print(self.circle.zRotation)
})
let sequence = SKAction.sequence([wait, block])
self.runAction(SKAction.repeatActionForever(sequence))
Run Code Online (Sandbox Code Playgroud)
这是我用于创建的代码SKShapeNode:
let tex:SKTexture = SKTexture(image: image)
let circle = SKShapeNode(circleOfRadius: 100 )
circle.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 200)
circle.strokeColor = SKColor.clearColor()
circle.glowWidth = 1.0
circle.fillColor = SKColor.whiteColor()
circle.fillTexture = tex
self.addChild(circle)
// Runing the action
circle.runAction(spin)
Run Code Online (Sandbox Code Playgroud)
请帮忙。提前致谢!
PS:我知道使用 anSKSpriteNode会更好,但我的目标是将方形图像放置在圆形框架中,我认为使用 anSKShapeNode会是完美的。如果有人知道如何创建通告 …
当键盘出现时,我试图将屏幕向上移动.我成功完成了它但我需要知道如何仅在UITextView单击底部时滚动视图,而不是顶部,TextView因为键盘只是触及TextView下面.
应用是这样的:
class viewControllerCuatro: UIViewController, UITextViewDelegate {
@IBOutlet weak var textViewInteriorUno: UITextView!
@IBOutlet weak var textViewInteriorDos: UITextView!
override func viewDidLoad() {
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Atrás", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
**NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: self.view.window)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: self.view.window)**
}
**func keyboardWillShow(sender: NSNotification) {**
// 1
let userInfo: [NSObject : AnyObject] = sender.userInfo!
// 2
let keyboardSize: CGSize = userInfo[UIKeyboardFrameBeginUserInfoKey]!.CGRectValue.size
let offset: CGSize = userInfo[UIKeyboardFrameEndUserInfoKey]!.CGRectValue.size
// 3
if keyboardSize.height …Run Code Online (Sandbox Code Playgroud) 我正在为iOS设备创建一个应用程序,它将监控一只股票的价格.我已经成功创建了一个函数,它从API中收集数据并打印出库存的当前值.
问题是,当我运行应用程序时,会打印一个(当前)价格并且它始终保持这样.
我的问题是如何使该功能在每个指定的时间内重复?
这是我的viewDidLoad,是我想要每隔几秒重复一次的功能.
码:
import Cocoa
class ViewController: NSViewController {
let baseURL = "url"
@IBOutlet weak var bitcoinValue: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
getJSON { (usdPrice) -> Void in
let usdPriceText = usdPrice.description
self.bitcoinValue.stringValue = usdPriceText
print(usdPrice)
}
}
func getJSON(completion: (Double) -> Void) {
let url = NSURL(string: baseURL)
let request = NSURLRequest(URL: url!)
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let task = session.dataTaskWithRequest(request) { (data, response, error) -> Void in
if error == nil{
let swiftyJSON = …Run Code Online (Sandbox Code Playgroud) 我正在尝试加载另一个,UIViewController以便我可以获取其中的数据IBOutlets。我正在使用 Swift 和 Sprite-Kit。在UIViewController我说的叫GameViewController。这是我的游戏中加载的第一件事。然后它转到我的GameScene. 这是我试图实例化我的GameViewController. 我想这样做是因为我正在使用一个名为的库,iCarousel并且我想将它从我的GameScene. 但是,iCarousel 只能用于UIViewController. 所以我想调用一个GameViewController将被调用的函数GameScene。在这个函数中,有一个NSLayoutConstraint用于移动转盘。每当我调用这个函数时,它都说它为零。这是我的一些代码:
在我的里面GameScene:
let storyboard: UIStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
let firstViewController: GameViewController = storyboard.instantiateViewControllerWithIdentifier("Load-up") as! GameViewController
firstViewController.start()
Run Code Online (Sandbox Code Playgroud)
在我的里面GameViewController:
func start() {
// Constraint
top.constant = 100
UIView.animateWithDuration(2){
self.view.layoutIfNeeded()
}
}
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,请随时问我。提前致谢!
swift ×5
ios ×3
animation ×1
iphone ×1
nstimer ×1
rotation ×1
skscene ×1
skshapenode ×1
sprite-kit ×1
uibutton ×1
uistoryboard ×1