好的,我遇到了一些问题UITextView.这是问题所在:
我添加了一些文字UITextView.然后用户双击以选择某些内容.然后我改变UITextView(以编程方式如上)和UITextView 滚动到页面底部的文本,其中有一个光标.
但是,这不是用户点击的地方.UITextView无论用户点击何处,它始终滚动到底部.
所以这是我的问题:UITextView每次更改文本时,如何强制滚动到顶部?我试过contentOffset和scrollRangeToVisible.都没有工作.
任何建议,将不胜感激.
我正在使用Swift编写应用程序,我需要显示警报.该应用必须兼容iOS 7和iOS 8.由于UIAlertView已被替换UIAlertController,如何在UIAlertController不检查系统版本的情况下检查是否可用?我听说Apple建议我们不要检查设备的系统版本,以确定API的可用性.
这就是我在iOS 8中使用的,但是在iOS 7上用" dyld: Symbol not found: _OBJC_CLASS_$_UIAlertAction" 崩溃了:
let alert = UIAlertController(title: "Error", message: message, preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
alert.addAction(cancelAction)
presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
如果我使用UIAlertView for iOS 8,我收到此警告: Warning: Attempt to dismiss from view controller <_UIAlertShimPresentingViewController: 0x7bf72d60> while a presentation or dismiss is in progress!
我正在维护一个基于SDK 6.0的旧iOS项目.
这个项目的方法称为
-(void) showComboBox:(UIView*)view:withOptions:(NSDictionary*)options
用于显示组合框.为了实现这一目标,它使用了UIActionSheet,这在iOS8上已弃用.
我的解决方案是这样的:
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8) {
UIAlertController* alertController = [UIAlertController
alertControllerWithTitle:@"title"
message:@"message"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* item = [UIAlertAction actionWithTitle:@"item"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//do something here
//inform the selection to the WebView
...
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:item];
[alertController addAction:cancelAction];
//I am not sure whether it's the right way
if ([view.nextResponder isKindOfClass:UIViewController.class]) {
UIViewController* vc = (UIViewController*)view.nextResponder;
[vc presentViewController:alertController animated:YES completion:nil]; …Run Code Online (Sandbox Code Playgroud) 如何使用MapKit从坐标获取地址?
当我在地图上长按它获取坐标时,我有这个代码:
func didLongPressMap(sender: UILongPressGestureRecognizer) {
if sender.state == UIGestureRecognizerState.Began {
let touchPoint = sender.locationInView(self.mapView)
let touchCoordinate = self.mapView.convertPoint(touchPoint, toCoordinateFromView: self.mapView)
var annotation = MKPointAnnotation()
annotation.coordinate = touchCoordinate
annotation.title = "Your position"
self.mapView.addAnnotation(annotation) //drops the pin
println("lat: \(touchCoordinate.latitude)")
var num = (touchCoordinate.latitude as NSNumber).floatValue
var formatter = NSNumberFormatter()
formatter.maximumFractionDigits = 4
formatter.minimumFractionDigits = 4
var str = formatter.stringFromNumber(num)
println("long: \(touchCoordinate.longitude)")
var num1 = (touchCoordinate.longitude as NSNumber).floatValue
var formatter1 = NSNumberFormatter()
formatter1.maximumFractionDigits = 4
formatter1.minimumFractionDigits = 4
var str1 = formatter1.stringFromNumber(num1) …Run Code Online (Sandbox Code Playgroud) 我在转换Objective-C代码为Swift创建目录时遇到了一些麻烦.
Objective-C的:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
Run Code Online (Sandbox Code Playgroud) 如何检测UITextViewwith中的数据更改Swift?以下代码不进行任何检测.
我宣布UITextView:
@IBOutlet weak var bodyText: UITextView!
optional func textViewDidChange(_ textView: UITextView!) {
println(bodyText.text)
}
Run Code Online (Sandbox Code Playgroud)
谢谢斯科特
是否可以像在原始应用程序中那样在swift的今天扩展中使用我的CoreData模型?如果是,我该如何创建NSManagedObjectContext?
我真的不知道,除了group-identifier之外,但不幸的是我不知道如何获取上下文..
过去我创建的应用程序在开头检查我想要使用CoreData然后我得到了managedObjectContext通过我的AppDelegate ..但我怎么能在扩展中做那样的想法?Apple不提供相关信息..
我在AppDelegate中编辑了这一行:
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"HTWcampus.sqlite"];
Run Code Online (Sandbox Code Playgroud)
对此(在将组包括在两个目标之后):
NSURL *storeURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.BenchR.TodayExtensionSharingDefaults"];
storeURL = [storeURL URLByAppendingPathComponent:@"HTWcampus.sqlite"];
NSLog(@"StoreURL2: %@", storeURL);
Run Code Online (Sandbox Code Playgroud)
有了这个,我的应用程序中的现有数据库就消失了(这很棒,因为我认为将数据库放在共享段中是有效的).
但是如何在扩展中创建我的上下文实例?我怎样才能访问我的NSManagedObject-subclasses?
在扩展中,我有这个代码到目前为止:
var context: NSManagedObjectContext!
override func viewDidLoad() {
super.viewDidLoad()
var storeURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.BenchR.TodayExtensionSharingDefaults")
storeURL = storeURL?.URLByAppendingPathComponent("HTWcampus.sqlite")
let modelURL = NSBundle.mainBundle().URLForResource("HTWcampus", withExtension: "momd")
let model = NSManagedObjectModel(contentsOfURL: modelURL)
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: model)
coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: nil)
context = NSManagedObjectContext()
context.persistentStoreCoordinator = coordinator
}
Run Code Online (Sandbox Code Playgroud)
这是正确的吗?如果是的话,我怎样才能获得我的NSManagedObject-Subclasses?我是否必须将momd文件添加到扩展目标?如果是的话,我该怎么做?
当我向a添加子视图UIView时,或者当我调整现有子视图的大小时,我希望[view sizeToFit]并[view sizeThatFits]反映出这种变化.但是,我的经验是sizeToFit什么都不做,并sizeThatFits在更改之前和之后返回相同的值.
我的测试项目有一个包含单个按钮的视图.单击该按钮会向视图添加另一个按钮,然后调用sizeToFit包含视图.在添加子视图之前和之后,视图的边界将转储到控制台.
- (void) logSizes {
NSLog(@"theView.bounds: %@", NSStringFromCGRect(theView.bounds));
NSLog(@"theView.sizeThatFits: %@", NSStringFromCGSize([theView sizeThatFits:CGSizeZero]));
}
- (void) buttonTouched {
[self logSizes];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10.0f, 100.0f, 400.0f, 600.0f);
[theView addSubview:btn];
[theView sizeToFit];
[self performSelector:@selector(logSizes) withObject:nil afterDelay:1.0];
}
Run Code Online (Sandbox Code Playgroud)
输出是:
2010-10-15 15:40:42.359 SizeToFit[14953:207] theView.bounds: {{0, 0}, {322, 240}}
2010-10-15 15:40:42.387 SizeToFit[14953:207] theView.sizeThatFits: {322, 240}
2010-10-15 15:40:43.389 SizeToFit[14953:207] theView.bounds: {{0, 0}, {322, 240}}
2010-10-15 15:40:43.391 SizeToFit[14953:207] …Run Code Online (Sandbox Code Playgroud) 如何像iPhone中的预告片应用程序一样实现导航栏的实时模糊效果.
即当您滚动时,内容应该在导航栏后面变得模糊.请帮我一些代码.
谢谢!
我想达到这样的效果: -

objective-c uinavigationbar uinavigationcontroller ios swift
我只需要UIDatePicker选择月份和年份.我检查了班级参考文件.看起来像是UIDatePicker一个UIView.我想象的UIPickerView可能是一个子视图,如果我可以抓住它,我可以隐藏组件.但不是.那是不可能的.我必须创建自己的自定义选择器吗?有任何想法吗?
ios ×10
swift ×6
objective-c ×4
iphone ×2
uitextview ×2
clgeocoder ×1
clplacemark ×1
core-data ×1
ios8 ×1
mapkit ×1
resize ×1
uialertview ×1
uibutton ×1
uidatepicker ×1
uikit ×1
uipickerview ×1
uiview ×1