我正在使用Swift进行iOS编程,我正在使用此代码移动UITextField,但它不起作用.我keyboardWillShow正确调用该函数,但文本字段不移动.我正在使用autolayout.
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self);
}
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
//let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
var frame = self.ChatField.frame
frame.origin.y = frame.origin.y - keyboardSize.height + 167
self.chatField.frame = frame
println("asdasd")
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Swift中上传带参数的图像.当我尝试这段代码时,我可以得到参数而不是图像
uploadFileToUrl(fotiño:UIImage){
var foto = UIImage(data: UIImageJPEGRepresentation(fotiño, 0.2))
var request = NSMutableURLRequest(URL:NSURL(string: "URL"))
request.HTTPMethod = "POST"
var bodyData = "id_user="PARAMETERS&ETC""
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
request.HTTPBody = NSData.dataWithData(UIImagePNGRepresentation(foto))
println("miraqui \(request.debugDescription)")
var response: AutoreleasingUnsafeMutablePointer<NSURLResponse?>=nil
var HTTPError: NSError? = nil
var JSONError: NSError? = nil
var dataVal: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse: response, error: &HTTPError)
if ((dataVal != nil) && (HTTPError == nil)) {
var jsonResult = NSJSONSerialization.JSONObjectWithData(dataVal!, options: NSJSONReadingOptions.MutableContainers, error: &JSONError)
if (JSONError != nil) {
println("Bad JSON")
} else {
println("Synchronous\(jsonResult)")
}
} …Run Code Online (Sandbox Code Playgroud) 如何使用Swift创建自定义警报?我尝试从Objective c翻译指南但加载全屏布局
为了方便我可以加载透明背景的新布局我试试这个:
listaalertviewcontroller.view.backgroundColor = UIColor.clearColor()
let purple = UIColor.purpleColor() // 1.0 alpha
let semi = purple.colorWithAlphaComponent(0.5)
listaalertviewcontroller.view.backgroundColor = semi
presentingViewController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentViewController(listaalertviewcontroller, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在动画中它是透明的,但是当动画结束时它是不透明的......我在视图中关闭了不透明的选项......我做错了什么?
我正在尝试解析来自php的信息,但我需要发送一个字典参数,所以我尝试了一些东西......我看到了教程,例子但我被卡住了所以我回到了开头:(这是什么好方法这样做?)
func asd(){
let urlPath = "http://xxxxx.php"
let url: NSURL = NSURL(string: urlPath)
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "GET"
var parm = ["id_xxxx": "900"] as Dictionary
//I THINK MY PROBLEM IT'S HERE! i dont know how to link parm with session, i try is with session.uploadTaskWithRequest(<#request: NSURLRequest?#>, fromData: <#NSData?#>) but doesn't work
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
println("Task completed")
if(error) {
// If there is an error in …Run Code Online (Sandbox Code Playgroud) 我是iOs和swift的新手,我不知道如何以yyyy-mm-dd格式给出一天,并在一周中的某一天给出功能响应,例如:
2014-08-04 - >周一([0])
谢谢
swift ×5
ios ×4
calendar ×1
cocoa-touch ×1
dictionary ×1
file-upload ×1
image ×1
json ×1
keyboard ×1
parsing ×1
uialertview ×1
uitextfield ×1