我查了很多这种方法的例子,但仍然无法弄清楚我在做什么.我正在尝试在当前视图下添加另一个视图,然后在用户单击当前屏幕上的按钮时删除当前视图.由于某种原因,视图消失了,但我没有看到应该低于它的视图.我只是一个白色的屏幕.
这是我当前的ViewDidLoad(顶部的那个 - 为了示例的ViewControllerTop)视图:
- (void)viewDidLoad
{
[super viewDidLoad];
viewControllerBottom = [[ViewControllerBottom alloc] init];
[self.view insertSubview:viewControllerBottom.view belowSubview:self.view];
}
Run Code Online (Sandbox Code Playgroud)
按照这种方法,有一种方法在用户点击按钮后触发:
- (IBAction)goToBottomView:(id)sender {
[self.view.superview removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
有没有人看到这个有什么问题?谢谢您的帮助!
顺便说一句 - 即使它很愚蠢,我也尝试使用insertSubview:aboveSubview但它也不起作用.
我SKAction以这种方式创造了我:
unicornAction = [SKAction followPath:mypath asOffset:NO orientToPath:YES duration:0.1];
Run Code Online (Sandbox Code Playgroud)
并将其添加到我的SKSprite:
[sprite runAction:[SKAction repeatActionForever:unicornAction] withKey:@"move"];
Run Code Online (Sandbox Code Playgroud)
我这样做是为了让我可以在精灵运动中随时调整速度.
当我的精灵到达路径的末尾时,我需要一个回调,以便我可以删除精灵.我怎么能得到这样的回调?
另外,有没有更好的方法来使用SKAction我想要做的事情,同时允许我在动作运行期间的任何地方改变速度?
我们可以在viewdidload中创建像此代码一样的自定义键盘,如Apple开发者网站所示.
self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.nextKeyboardButton addTarget:self action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.nextKeyboardButton];
NSLayoutConstraint *nextKeyboardButtonLeftSideConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
NSLayoutConstraint *nextKeyboardButtonBottomConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[self.view addConstraints:@[nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]];
Run Code Online (Sandbox Code Playgroud)
但是,有1个问题.当我们以纵向运行该程序时,自定义键盘的高度约为220.然后我们改为横向.它小于220.奇怪的是,当我回到纵向视图时,高度不再是220,它与景观高度相同.它永远不会回到原来的高度.那么,有没有办法改变我们将添加子视图的视图高度?
我正在尝试为iOS8编写自定义键盘,到目前为止,减去奇怪的打嗝,我没有太多问题.但是,当我创建一个视图并将其添加为UIButton我已添加到键盘视图的子视图时,新添加的视图将被剪切在键盘视图的顶部.据我所知,层次结构如下:
UIView(弹出) - > UIButton(实际"键") - >UIInputView
使用此层次结构,顶层UIView被剪切在内部UIInputView.每个UIView都clipsToBounds设置为false,我也将UIView(self.view)设置false为UIInputViewController,但似乎没有帮助.
可能这是目前对扩展系统的限制,但希望这是我正在做的傻事!
有没有办法在iOS 8自定义键盘扩展中替换预测文本的来源并在预测文本栏中显示?预测文本栏的类是什么?
非常感谢.我已经阅读了文档,但找不到答案.请帮忙.
Apple在2014年WWDC中引入了"Widgets"的概念.Widgets用于快速访问具有急需信息的应用程序.我试图将Widgets添加到我的应用程序中.当我们在应用程序中只有一个Target时很容易.
但是,如果我们有多个目标,似乎我们需要为每个目标添加单独的Widget.是否可以添加一个Widget并使其与所有目标共享?
提前致谢.
我通过桥接头在我的Swift项目中使用Objective-C类.方法签名看起来像这样:
- (CFArrayRef)someMethod:(someType)someParameter;
Run Code Online (Sandbox Code Playgroud)
我开始获取类的实例,调用方法,并存储值:
var myInstance = MyClassWithThatMethod();
var cfArr = myInstance.someMethod(someValue);
Run Code Online (Sandbox Code Playgroud)
然后尝试在数组中获取一个值:
var valueInArrayThatIWant = CFArrayGetValueAtIndex(cfArr, 0);
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误Unmanaged<CFArray>' is not identical to 'CFArray'.是什么Unmanaged<CFArray>,甚至什么意思?
我查看了如何将CFArray转换为Swift数组?但我不需要将数组转换为swift数组(但这样会很好).我只需要能够从数组中获取值.
我也尝试过传递给这个答案中CFArray概述的函数的方法:
func doSomeStuffOnArray(myArray: NSArray) {
}
Run Code Online (Sandbox Code Playgroud)
但是在使用它时会出现类似的错误:
doSomeStuffOnArray(cfArr); // Unmanaged<CFArray>' is not identical to 'NSArray'
Run Code Online (Sandbox Code Playgroud)
我使用的CFArray,因为我需要存储阵列CGPathRef,它不能被储存在NSArray.
那么我应该如何CFArray在Swift中使用?
我有一个DataManager类,它返回一个共享实例:
+ (DataManager *)sharedInstance;
{
static DataManager *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [[DataManager alloc] init];
});
return sharedInstance;
}
Run Code Online (Sandbox Code Playgroud)
在这里,我跟踪我的managedObjectContext,managedObjectModel,persistentStoreCoordinator.
我还有一种方法可以拉出用于显示的项目:
- (NSArray *)getItems
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
return [[self managedObjectContext] executeFetchRequest:fetchRequest error:nil];
}
Run Code Online (Sandbox Code Playgroud)
现在在我的主应用程序中,当我调用此getItems然后单独修改项目时,我有一个视图控制器.例如,set item.itemName = @"testName"; 然后调用我的save方法.
我也有一个iOS 8,在我的TodayViewController中我也调用了getItems方法.我有一个NSNotification,它检测managedObjectContext保存.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refetchItems) name:NSManagedObjectContextDidSaveNotification object:[[DataManager sharedInstance] managedObjectContext]];
Run Code Online (Sandbox Code Playgroud)
这些重新获取的项目会被调用,但会返回过时的NSManagedObjects.例如,itemName没有更改为@"testName".
我哪里错了?如果您需要查看任何其他代码,请告诉我们.
谢谢!
我们可以在iOS 8(Xcode Beta版)的其他视图中使用NSlog进行登录.
但是,我不能在KeyboardViewController的键盘扩展中使用NSLog.它没有出现在日志中.
NSLog(@"键盘中的viewdidload");
我想知道如何实时检测/登录.
我正在尝试从扩展程序启动容器应用程序.(一个Action扩展)容器应用程序有一个工作URL方案(例如://),我可以通过在Safari中导航到该URL来验证这一点.
当我尝试使用 - [NSExtensionContext openURL:completionHandler:]来启动容器应用程序时,我得到一个不成功的回调,没有任何反应.
iOS 8 Beta 2更改说openURL方法现在应该可以正常工作,但这仍然是一个错误还是我做错了什么?
我的项目遇到了一个恼人的问题...当我录制一些内容并在模拟器中播放时,一切正常。但是当我在 iPhone 上播放它时,声音不起作用...我花了几个小时寻找解决方案...
这是我的代码
import UIKit
import Parse
import AVFoundation
class View1: UIViewController, AVAudioRecorderDelegate, AVAudioPlayerDelegate {
@IBOutlet weak var recordButton: UIButton!
@IBOutlet weak var playButton: UIButton!
var soundRecorder: AVAudioRecorder!
var soundPlayer:AVAudioPlayer!
let fileName = "sound.caf"
override func viewDidLoad() {
super.viewDidLoad()
setupRecorder()
}
@IBAction func recordSound(sender: AnyObject) {
if (sender.titleLabel?!.text == "Record"){
soundRecorder.record()
sender.setTitle("Stop", forState: .Normal)
playButton.enabled = false
} else {
soundRecorder.stop()
sender.setTitle("Record", forState: .Normal)
}
}
@IBAction func playSound(sender: AnyObject) {
if (sender.titleLabel?!.text == "Play"){
recordButton.enabled = false
sender.setTitle("Stop", …Run Code Online (Sandbox Code Playgroud) 我试过了[self.extensionContext openURL:completion],但我的应用程序崩溃了.我听说有些扩展无法使用此方法,可以使用iMessage扩展吗?
顺便说一句,主持应用程序可以激活其iMessage扩展吗?
我是icloud的新手.我正在寻找如何以严谨的方式做到这一点.但我的问题是我是否必须实施核心数据来存储icluod上的文件?我该怎么做?有没有人有关于icloud的好教程?
我有这个代码
-(NSString *)archivePathWithName:(NSString*) name {
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:name];
}
Run Code Online (Sandbox Code Playgroud)
然后我就这样保存
[NSKeyedArchiver archiveRootObject:items toFile:[self archivePathWithName:name]];
Run Code Online (Sandbox Code Playgroud)
是在iCloud保存?