基本上我正在尝试实现一个动画,它将在返回原始文本之前将标签的文本替换几秒钟.我已经设法让标签在3秒后更改文本并淡出,但是我无法弄清楚如何在动画完成后将文本返回到原始状态.
这是我目前拥有的:
@IBAction func fade() {
userMessageLabel.alpha = 100
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(3)
userMessageLabel.text = "Name is not valid!"
userMessageLabel.alpha = 0
UIView.commitAnimations()
}
Run Code Online (Sandbox Code Playgroud)
我需要文字标签返回"请输入你的名字"
任何帮助将非常感激.
我决定避免使用自动布局,所以我正在尝试实现代码,以使我的应用程序根据屏幕大小管理两个不同的故事板.
我一直在关注这个教程:http://pinkstone.co.uk/how-to-load-a-different-storyboard-depending-on-screen-size-in-ios/
我在尝试将Objective C代码转换为Swift时遇到问题.
这是我目前在AppDelegate中的代码:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func grabStoryboard() -> UIStoryboard {
var storyboard = UIStoryboard()
var height = UIScreen.mainScreen().bounds.size.height
if height == 480 {
storyboard = UIStoryboard(name: "Main3.5", bundle: nil)
} else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
return storyboard
}
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
var storyboard: UIStoryboard = self.grabStoryboard()
self.window?.rootViewController.storyboard.instantiateInitialViewController()
self.window?.makeKeyAndVisible()
return true …Run Code Online (Sandbox Code Playgroud) 我一直在尝试在导航栏中设置文本的字体大小和字体颜色,但是我遇到了问题.
基本上似乎正在发生的是我的两行代码相互覆盖,我只能让它们自己工作.
这是我的代码:
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir", size: 30)]
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
Run Code Online (Sandbox Code Playgroud)
我需要更改什么才能更改字体大小和颜色?
我的单元格中有一个标签,我想在点击时显示/隐藏.我知道我必须得到从内部轻敲的单元格的索引路径didSelectRowAtIndexPath.但我不确定如何在特定单元格中显示/隐藏标签.
我可以从内部显示/隐藏它didSelectRowAtIndexPath,还是有办法处理它cellForRowAtIndexPath然后更新它?
我做了一些研究,但我真的找不到很多东西.
以下是我到目前为止的所有内容:
var selectedRowIndex: NSIndexPath = NSIndexPath(forRow: -1, inSection: 0)
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedRowIndex = indexPath
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试更改我的应用程序中导航栏的文本颜色,但我无法弄清楚它是如何完成的.在Xcode 6 beta 2之前我使用的是:
navigationController.navigationBar.titleTextAttributes = [UITextAttributeTextColor: UIColor.whiteColor()]
Run Code Online (Sandbox Code Playgroud)
这工作得非常好但是在更新到新版本之后我只是得到一个错误,说明'titleTextAttributes'在Swift中不可用.
另外,如何更改状态栏的文本颜色?我已经尝试在Attributes检查器中更改它,我也尝试通过代码遵循Objective C示例,但我仍然无法让它工作.
我确信这个问题有一个明显的解决方案,但我已经尝试了一段时间不同的东西,但我无法弄清楚。基本上我已经得到了两点之间的距离,并且我试图将它从 Double 转换为 Int(以删除所有小数点),但是我尝试过的一切都没有奏效。
这是我的代码:
let userLocation = CLLocation(latitude: mapView.userLocation.coordinate.latitude, longitude: mapView.userLocation.coordinate.longitude)
let annotationLocation = CLLocation(latitude: latitudePassed, longitude: longitudePassed)
var distance = CLLocationDistance(annotationLocation.distanceFromLocation(userLocation))
if distance > 1000 {
distance = distance / 1000
rideAnnotation.subtitle = "\(distance) kilometer(s)"
} else {
rideAnnotation.subtitle = "\(distance) meters"
}
Run Code Online (Sandbox Code Playgroud)
我尝试先转换为字符串,然后转换为 int,再转换为 inttoInt()和其他一些东西,但没有成功。
有人有什么建议吗?
我刚刚更新到Xcode 7和Swift 2.0,当然它在我的应用程序中引起了一些问题.我已经解决了很多问题,但我正在努力解决这个问题.
在我的表视图中,我正在从Parse.com加载图像,但由于某种原因,图像没有显示在AsyncImageView中.这段代码在更新之前完美运行,所以我不确定问题是什么:
AsyncImageLoader.sharedLoader().cancelLoadingURL(cell.rideImageView.imageURL)
cell.rideImageView.image = UIImage(named: "Unloaded")
cell.rideImageView.imageURL = NSURL(string: ride.rideImageSmall!)
Run Code Online (Sandbox Code Playgroud)
我已经检查过以确保从Parse正确加载图像URL,确实如此.这是我正在使用的库:https://github.com/nicklockwood/AsyncImageView
有人有主意吗?
我的应用程序中有一些代码可以在单击时扩展单元格.问题是我还没弄明白如何只扩展已被挖掘的单元格.目前我的代码只扩展了所有单元格.
这是我的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedRowIndex = indexPath
tableView.beginUpdates()
tableView.endUpdates()
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == selectedRowIndex.row {
if cellTapped == false {
cellTapped = true
return 141
} else {
cellTapped = false
return 70
}
}
return 70
}
Run Code Online (Sandbox Code Playgroud)
我只需要扩展已被挖掘的单元格,我需要做什么?
我有三个InterfaceControllers,我提供代码:
self.presentControllerWithName("new", context: self)
Run Code Online (Sandbox Code Playgroud)
由于某种原因,连接到主控制器(带有segue)的InterfaceControllers显示右上角的时间,而上面代码显示的那些不显示.
这是因为我呈现控制器的方式,还是有其他原因?如果是这样,有人知道解决方案吗?
我刚刚完成了我的第一个应用程序并且已经在本地化了不同的功能.我的应用程序中有一个功能,我不确定是否可以进行本地化.
基本上,当用户打开我的应用程序时,会收到一条消息,上面写着"下午好","早上好"或"晚上好".我创建了一些代码来检查时间的前缀,以决定显示什么消息,但是由于不同的国家/地区格式化时间不同,我不确定如何将其本地化.
我是否必须弄清楚它确实在哪些国家工作,并添加一个if语句来决定该应用是否可以显示此问候语?否则根据他们的名字显示问候语?
这是我的代码:
var date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .ShortStyle
let time = dateFormatter.stringFromDate(date)
var currentTimeOfDay = ""
if time.hasPrefix("0") {
currentTimeOfDay = "morning"
} else if time.hasPrefix("10") {
currentTimeOfDay = "morning"
} else if time.hasPrefix("11") {
currentTimeOfDay = "morning"
} else if time.hasPrefix("12") {
currentTimeOfDay = "morning"
} else if time.hasPrefix("13") {
currentTimeOfDay = "afternoon"
} else if time.hasPrefix("14") {
currentTimeOfDay = "afternoon"
} else if time.hasPrefix("15") {
currentTimeOfDay = "afternoon"
} else if …Run Code Online (Sandbox Code Playgroud) 我刚刚更新到最新的Xcode 6.3测试版,我收到一个错误,我无法找到解决方案.
当我运行我的应用程序时,我收到错误:Command failed due to signal: Segmentation Fault 11.我查看了完整的错误消息,并且我已经完成了我认为相关的部分:
(unresolved_dot_expr type='@lvalue String!' location=/Filename/FifthViewController.swift:423:19 range=[/Filename/FifthViewController.swift:423:9 - line:423:19] field 'text'
(declref_expr type='UITextField' location=/Filename/FifthViewController.swift:423:9 range=[/Filename/FifthViewController.swift:423:9 - line:423:9] decl=AffordIt.(file).FifthViewController.func decl.textField@/Filename/FifthViewController.swift:418:34 specialized=yes))
Run Code Online (Sandbox Code Playgroud)
和
While emitting SIL for 'textFieldDidChangeValue' at /Filename/FifthViewController.swift:418:5
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?显然我已经用'Filename'替换了完整路径.这是与错误相关的代码:
textField.addTarget(self, action: "textFieldDidChangeValue:", forControlEvents: UIControlEvents.EditingChanged)
func textFieldDidChangeValue(textField: UITextField) {
//Automatic formatting for transaction value text field. Target is added above.
var text = textField.text.stringByReplacingOccurrencesOfString(currencyFormatter.currencySymbol!, withString: "").stringByReplacingOccurrencesOfString(currencyFormatter.groupingSeparator, withString: "").stringByReplacingOccurrencesOfString(currencyFormatter.decimalSeparator!, withString: "").stringByReplacingOccurrencesOfString(" ", withString: "") // There is a special character here. This …Run Code Online (Sandbox Code Playgroud) 在更新到Xcode 7之后,我刚刚将我的项目更新为Swift 2.0,并且我的手表扩展程序遇到了问题.
我希望有一个watchOS 1目标,以及watchOS 2目标,所以我为watchOS 2应用程序创建了第二个目标.问题是,我在这行的watchOS 1应用程序中收到错误:
WKInterfaceController.openParentApplication(["parkName": park]) { userInfo, error in
Run Code Online (Sandbox Code Playgroud)
'openParentApplication(_:reply :)'不可用
我无法弄清楚为什么.有没有办法我需要指定这是一个watchOS 1应用程序?
有任何想法吗?
编辑
我在扩展程序的构建设置中找到了这个,但没有选项可以将其更改为watchOS 1.
swift ×12
ios ×6
xcode ×3
uitableview ×2
apple-watch ×1
cllocation ×1
nslocale ×1
uilabel ×1
uistoryboard ×1
watchkit ×1
watchos ×1
watchos-2 ×1