Tag: ios

NSOperationqueue背景,下载图片

我创build了一个NSOperationQueue来下载图片(来自Twitter for Cell): NSOperationQueue *queue = [[NSOperationQueue alloc]init]; [queue addOperationWithBlock:^{ NSString *ImagesUrl = [[NSString alloc]initWithFormat:@"http://api.twitter.com/1/users/profile_image/%@",[[status objectForKey:@"user"]objectForKey:@"screen_name"]];; NSURL *imageurl = [NSURL URLWithString:ImagesUrl]; UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageurl]]; [[NSOperationQueue mainQueue]addOperationWithBlock:^{ if (img.size.width == 0 || [ImagesUrl isEqualToString:@"<null>"]) { [statusCell.imageCellTL setFrame:CGRectZero]; statusCell.imageCellTL.image = [UIImage imageNamed:@"Placeholder"] ; }else [statusCell.imageCellTL setImage:img]; 这工作正常,但当它似乎移动滚动和查看图像仍在加载,他们正在改变几次,直到你得到一张照片。 而且我不喜欢诊断时间轮廓,所以我想以某种方式在后台创build这个NSOperationQueue 也可以展示如何使一个“Imagecache”不需要下载已经下载的图像。 **(状态= Twitter时间轴的NSDictionary)。 编辑:(所有单元格) – (UITableViewCell […]

Facebook iOS SDKlogin本地和UIWebViewlogin

对于我正在开发的应用程序,我需要用户能够使用本地SDKlogin到Facebook,但是在web视图中也有一个使用FB注释小部件的应用程序的单独部分。 问题出在用户使用原生SDKlogin后,他们没有login到webview注释部件中。 有没有办法让用户login使用本机iOS SDK,然后也login到UIWebView中的Facebook。 我尝试使用openAccessTokenFromData:completionHandler:在用户login后的FBSession类中,但不能得到这个工作,就像下面 – (void)didLogin { FBAccessTokenData *data = [FBAccessTokenData createTokenFromString:[FBSession activeSession].accessTokenData.accessToken permissions:[FBSession activeSession].accessTokenData.permissions expirationDate:[FBSession activeSession].accessTokenData.expirationDate loginType:FBSessionLoginTypeWebView refreshDate:nil]; [[FBSession activeSession] closeAndClearTokenInformation]; FBSession *session = [[FBSession alloc] init]; [session openFromAccessTokenData:data completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { }]; }

我如何使用iOS SDK的Swift REPL

我可以用iOS SDK运行Swift REPL吗? 我想在REPL中导入和使用UIKit ,但没有成功。 $ xcrun –sdk iphonesimulator8.1 –show-sdk-path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk $ xcrun –sdk iphonesimulator8.1 swift Welcome to Swift! Type :help for assistance. 1> import UIKit /var/folders/kb/xgglxb597sv6h8b744d5vft00000gn/T/lldb/92014/repl1.swift:2:8: error: no such module 'UIKit' import UIKit ^ $ swift -sdk `xcrun –sdk iphonesimulator8.1 –show-sdk-path` Welcome to Swift! Type :help for assistance. 1> import UIKit /var/folders/kb/xgglxb597sv6h8b744d5vft00000gn/T/lldb/91881/repl1.swift:2:8: error: no […]

Iphonesdk合并三个图像两个单一的图像

我正在iphone应用程序,我必须合并三个图像,使他们单一的形象。 我的意思是说我有一个背景图像,一个标题图像和较低的图像,我需要结合所有这一切,使一个单一的图像,所以我可以用它张贴到Facebook。 谢谢。 * 编辑 *我知道这两个图像的代码,但我怎样才能使用它的三个图像: UIGraphicsBeginImageContext(saveView.bounds.size); [saveView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();

禁用iOS Overscroll,但允许正文滚动

我想禁用iOS应用程序在Web应用程序中的滚动,但仍然允许滚动。 $(document).on('touchmove', function(e) { e.preventDefault(); }); 完全禁用滚动(如预期的那样)。 有没有办法做我想做的事情?

更改UITable部分backgroundColor而不丢失部分标题

我已经改变了我的tableviews部分的backgroundColor / backgroundImage。 我使用普通的tableView。 不用担心,这个代码没有问题的工作: -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 728, 40)] autorelease]; sectionView.backgroundColor = [UIColor greenColor]; //For using an image use this: //sectionView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]]; return sectionView; } 现在的问题是, 节标题不见了。 我用这个代码设置部分的标题: – (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){ return @""; } else […]

重新加载故事板来改变语言环境

我正在为我的应用程序使用一个本地化的Storyboard。 该应用程序必须有一个选项,即时改变语言。 到目前为止,我已经想出了如何更改应用程序启动期间使用的语言: [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", @"en", @"fr", nil] forKey:@"AppleLanguages"]; [[NSUserDefaults standardUserDefaults] synchronize]; //to make the change immediate 并设法通过删除关键窗口的所有子视图重新加载我的整个应用程序,从故事板重新加载初始视图控制器,并使其成为新的根视图控制器。 (它有一些问题,比如pipe理开放资源,但可以完成。) 我唯一无法弄清楚的是如何强制iOS用新语言重新加载故事板? 看起来故事板是以某种方式caching的,并且-UIStoryboad:stroyboardWithName:fromNib不会完全重新加载它,所以它出现在最后一种语言中。 我已经考虑了另外两个select: 有不同的故事板文件为每种语言(这是不可pipe理的,我不想这样做) 在我的所有视图控制器中使用事件侦听器来响应语言变化,并在UI上设置新的string(每次从故事板实例化时都必须调用这些string)。 这个解决scheme需要更多的时间,比我们想要花费的时间更多,同时也极大地增加了错误的可能性。 有没有更聪明的方法? 我不想保持我的应用程序的当前状态,所以重新启动它,就像它被杀死和实现似乎是一个合理的解决scheme。

如何使用“自动布局”为纵向和横向定向configuration不同的布局?

我有一个像附图中的视图 现在我添加约束条件,当方向改变为横向时,视图中的UITextview必须位于屏幕的右侧。 在UItextview上,我添加了下面的约束, 尾随空间:Superview 底部空间:Superview 虽然这些限制显示了一些关于ambugity的警告,但为我做了这个工作。 以下是横向模式的截图。 我的问题是,虽然UItextview被移动到右侧,我想要在横向模式下超级视图顶部的一些额外的宽度。 换句话说,我希望UITextview从现在处于横向模式的位置向下移动一点。 我在思考如何在IB中使用自动布局来做这件事,而我无法想象如何。 任何build议,请。

如何在用户通知中设置重复频率

直到iOS 9我们写这样的local notifications UILocalNotification* localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = pickerDate; localNotification.alertBody = self.textField.text; localNotification.timeZone = [NSTimeZone defaultTimeZone]; localNotification.repeatInterval = NSCalendarUnitMinute; localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 并在本地通知我们有repeatInterval ,现在在WWDC2016苹果宣布其中包含User Notification UNTimeIntervalNotificationTrigger。 UNCalendarNotificationTrigger。 UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60 repeats:YES]; 上面的代码会在每分钟后触发通知。 但是不能设定date。 NSDateComponents* date = [[NSDateComponents alloc] init]; date.hour = 8; date.minute […]

CG Gradient在模拟器上运行,但不在iPhone上运行

我有一个编译没有问题的代码。 它在iPhone模拟器上运行良好,但在我的设备上,我得到了一个EXC_BAD_ACCESS。 这发生在一个帮助函数绘制渐变。 我遵循这个教程来做到这一点。 我有的代码如下: – (void) drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGColorRef whiteColor = [UIColor whiteColor].CGColor; CGColorRef lightGrayColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0].CGColor; CGColorRef separatorColor = [UIColor colorWithRed:208.0/255.0 green:208.0/255.0 blue:208.0/255.0 alpha:1.0].CGColor; CGRect paperRect = self.bounds; CGRect nameRect = self.nameLabel.frame; CGPoint sepStartPoint = CGPointMake(nameRect.origin.x, nameRect.origin.x + nameRect.size.height + 2); CGPoint sepEndPoint = CGPointMake(nameRect.origin.x […]