Tag: ios

NSURLConnection委托方法

我很难findNSURLConnection委托方法实现的任何示例。 我想用一个button点击一个HTTPpost发送数据。 不知道如何使“提交”屏幕和“提交”。 (我知道如何使用微调,并将使用它们) 我正在使用此代码根据botton单击操作,但无法使用任何代表的东西。 不知道如何实现他们与我目前的设置。 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://myURL.com"]]; [request setHTTPMethod:@"POST"]; NSString *postString = [wait stringByAppendingString:co]; [request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"]; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; //[[NSURLConnection alloc] initWithRequest:request delegate:self]; [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; [SVProgressHUD dismissWithSuccess:@"Submission Successful"];

如何从本地path加载图像ios swift(按path)

在我的应用程序中,我将图像存储在本地存储中,并将该图像的path保存在数据库中。 我怎样才能从该path加载图像? 这里是我用来保存图像的代码: let myimage : UIImage = UIImage(data: data)! let fileManager = NSFileManager.defaultManager() let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) let documentDirectory = urls[0] as NSURL print(documentDirectory) let currentDate = NSDate() let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = .NoStyle dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let convertedDate = dateFormatter.stringFromDate(currentDate) let imageURL = documentDirectory.URLByAppendingPathComponent(convertedDate) imageUrlPath = imageURL.absoluteString print(imageUrlPath) UIImageJPEGRepresentation(myimage,1.0)!.writeToFile(imageUrlPath, […]

如何在Swift中列出符合协议的所有类?

如何列出在Swift中实现给定协议的所有类? 假设我们有一个例子: protocol Animal { func speak() } class Cat:Animal { func speak() { print("meow") } } class Dog: Animal { func speak() { print("Av Av!") } } class Horse: Animal { func speak() { print("Hurrrr") } } 这是我目前的(不可编译的)方法: func getClassesImplementingProtocol(p: Protocol) -> [AnyClass] { let classes = objc_getClassList() var ret = [AnyClass]() for cls […]

使用CAAnimationGroup进行序列animation

我正在尝试制作一系列animation,我在CAAnimationGroupfind了实现该对象的正确类。 在实践中,我添加了一个视图不同的子视图,我想animation他们的入口具有反弹效果,事实是,我希望看到他们的animation发生在前一个完成后。 我知道我可以设置代表,但我认为CAAnimationGroup是正确的select。 后来我发现组animation只能属于一层,但是我需要在屏幕上的不同层次上。 当然,托pipe层不起作用。 有些build议? – (void) didMoveToSuperview { [super didMoveToSuperview]; float startTime = 0; NSMutableArray * animArray = @[].mutableCopy; for (int i = 1; i<=_score; i++) { NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject: self.greenLeaf]; UIImageView * greenLeafImageView = [NSKeyedUnarchiver unarchiveObjectWithData: archivedData]; greenLeafImageView.image = [UIImage imageNamed:@"greenLeaf"]; CGPoint leafCenter = calculatePointCoordinateWithRadiusAndRotation(63, -(M_PI/11 * i) – M_PI_2); […]

Objective-C类别和新的iVar

我尝试将cocos2d的SimpleAudioEngine的function扩展为能够连续播放几种音效的function。 我试图用扩展名来做到这一点。 然而,我现在意识到,我可能还需要一个iVar记住所有声音文件的名称,并记住哪个声音正在播放。 但是,似乎我不能在一个类别中添加iVars。 相反,我试图使用扩展名,但似乎他们需要在类的原始.m文件,这样也行不通。 有没有另外一种方法,让我做到这一点? 标题与类别 #import <Foundation/Foundation.h> @interface SimpleAudioEngine(SoundChainHelper)<CDLongAudioSourceDelegate> -(void)playSoundChainWithFileNames:(NSString*) filename, …; @end 和扩展名为.m的文件: #import "SoundChainHelper.h" @interface SimpleAudioEngine() { NSMutableArray* soundsInChain; int currentSound; } @end @implementation SimpleAudioEngine(SoundChainHelper) // read in all filenames and start off playing process -(void)playSoundChainWithFileNames:(NSString*) filename, … { soundsInChain = [[NSMutableArray alloc] initWithCapacity:5]; va_list params; va_start(params,filename); while (filename) { [soundsInChain […]

以编程方式将应用程序发送到后台

有没有办法将应用程序发送到后台? 与您如何调用XCUIApplication.terminate()类似,我有一些UI元素可以在applicationDidBecomeActive(_:)上进行testing。 有谁知道这是否可能?

在使用LLVM-GCC编译ARC文件时,在“strong”之前获得“期望的属性”属性

我有一个包含一些使用ARC的文件的项目,有些则不是。 没有禁用ARC的编译器标志。 这工作正常。 我也想确保我的库编译LLVM-GCC和LLVM编译器。 我有这样一个属性: @property (strong, nonatomic) NSString *foo; 但是,当我在LLVM-GCC中编译时,我得到: “在”强“之前预期属性属性” 如果我强调保留,它编译好。 在LLVM编译器中强也工作正常。 我错过了什么? 保留不强的代名词?

当我使用UIImagePNGRepresentation或UIImageJPEGRepresentation将UIImage转换为NSdata时,图像大小增加太多

当我使用UIImagePNGRepresentation或UIImageJPEGRepresentation将UIImage转换为NSdata时,图像大小增加太多。 重现步骤: 1)打开Xcode并select新项目作为基于单一视图的应用程序 2)打开ViewController.xib并添加两个button,名称为i)testing在线图像ii)testing本地图像 3)添加两个IBActions i) -(IBAction)ClickLocalImageTest:(id)sender; ii) -(IBAction)ClickOnLineImageTest:(id)sender; 4)将“在线testing图像”连接到“ -(IBAction)ClickOnLineImageTest:(id)sender ” 和“testing本地图像”为“ -(IBAction)ClickLocalImageTest:(id)sender ;” 5) -(IBAction)ClickLocalImageTest:(id)sender “ -(IBAction)ClickLocalImageTest:(id)sender ”方法如下 – (IBAction)ClickLocalImageTest:(id)sender { NSLog(@"*************Test Local Image****************\n"); NSString *path=[[NSBundle mainBundle] pathForResource:@"hero_ipad_retina" ofType:@"jpg"]; NSLog(@"Before testing image size is :<—- %u kb",[[NSData dataWithContentsOfFile:path] length]/1024); UIImage *img = [UIImage imageNamed:@"hero_ipad_retina.jpg"]; NSLog(@"UIImagePNGRepresentation: image size is—->: %u kb",[UIImagePNGRepresentation(img) length]/1024); NSLog(@"UIImageJPEGRepresentation with […]

在iOS应用程序中构build信息(build立date/时间应用程序)

我正在寻找一种方法来在iOS应用程序的构build过程中dynamic添加有关应用程序的信息。 在testing过程中,知道什么时候在我的设备上安装了应用程序,并且可能由谁来构build,这将是一件好事。 我想象一下settings.app中的一个部分,它将提供用于debugging的基本构build信息。 我不想在每次构build之前手动更新构build信息文件 – 应该dynamic生成数据。

如何在Swift中使用MapKit在两个位置之间绘制路线?

如何在Swift中使用MapKit在用户的当前位置与特定位置之间绘制路线 ? 我search了很多,但没有find任何有用的Swift特定的链接或教程。