我在为新iPhone运行/测试我的应用程序时遇到了一些麻烦.
当使用这个更新版本的XCode运行模拟器时,iPhone 4"在硬件 - >设备下不再可见".
我是否禁用了它或者我的XCode以某种方式被破坏了.
编辑:
不知何故,我的Xcode在通过rightmouseclick XCode 4.5运行我的应用程序时没有运行最新的Beta版本(即使它被列出).
当通过开发人员端口的安装文件(.dmg)运行XCode时,我能够运行iPhone 4"(iPhone 5)模拟器.
在App中,我使用了几个viewcontrollers.在一个viewcontroller上,一个观察者初始化如下:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"MyNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:@"MyNotification" object:nil];
Run Code Online (Sandbox Code Playgroud)
即使NSNotification在初始化之前移除了执行次数,myMethod:也可以通过相应视图控制器上的重复视图量来总结.
为什么会发生这种情况?如何避免myMethod:被调用一次以上.
注意:我通过使用断点确保多次调用postNotification时没有犯错.
编辑:这就是我的postNotification的样子
NSArray * objects = [NSArray arrayWithObjects:[NSNumber numberWithInt:number],someText, nil];
NSArray * keys = [NSArray arrayWithObjects:@"Number",@"Text", nil];
NSDictionary * userInfo = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:self userInfo:userInfo];
Run Code Online (Sandbox Code Playgroud)
编辑:甚至在我订阅了viewwillappear之后:我得到了相同的结果.myMethod:被多次调用.(我重新加载viewcontroller的次数).
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"MyNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:@"MyNotification" object:nil];
}
Run Code Online (Sandbox Code Playgroud)
编辑:我的生命周期似乎有些问题.ViewDidUnload和dealloc没有被调用,但是viewdiddisappear被调用.
我将Viewcontroller推送到堆栈的方式如下,其中parent是tableview子类(单击此viewcontroller启动的行:
detailScreen * screen = [[detailScreen alloc] initWithContentID:ID andFullContentArray:fullContentIndex andParent:parent];
[self.navigationController pushViewController:screen animated:YES];
Run Code Online (Sandbox Code Playgroud)
解:
将nsnotification移除到viewdiddisappear就可以了.感谢您的指导!
iphone nsnotifications uiviewcontroller nsnotificationcenter ios
我在我的iPhone应用程序中使用tesseract.
我在我的图像上尝试了几个滤镜,用于将其转换为灰度图像,但是我希望得到一个阈值设置的结果,以便图像内部的唯一像素为黑色或白色.
我成功地使用苹果灰度过滤器,它给出了适当的结果.然而,它仍然是一个16位图像(如果我错了,请纠正我).我目前使用的过滤如下:
- (UIImage *) grayishImage:(UIImage *)i {
// Create a graphic context.
UIGraphicsBeginImageContextWithOptions(i.size, YES, 1.0);
CGRect imageRect = CGRectMake(0, 0, i.size.width, i.size.height);
// Draw the image with the luminosity blend mode.
[i drawInRect:imageRect blendMode:kCGBlendModeLuminosity alpha:1.0];
// Get the resulting image.
UIImage *filteredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return filteredImage;
}
Run Code Online (Sandbox Code Playgroud)
谁能为我提供过滤器来获得纯黑白像素而不是灰度图像?
我正在制作支持游戏中心的应用程序.在排行榜页面中有一个像facebook一样的按钮.然而它被禁用了.它是否会在Appstore中出售时启用,还是需要在代码中进行其他配置?
将我的Google Glass更新到XE16后,我使用simpleadapter构建的listview无法再滚动.有没有办法手动启用滚动GDK或修复此问题?
我想在我的应用程序中实现一个功能,以便当用户不使用应用程序5分钟时,应用程序从一开始就运行而不是用户停止的位置.
我发现plist属性'Application不在后台运行',但是这个函数让App总是从一开始运行.有没有办法可以为这个plist属性设置一个计时器或者在伪代码中做同样的事情?
更新:
提到的方式是正确的.但是我正在寻找一种解决方案,让App在应用程序进入后台后注意到空闲时间.(即按下主页按钮后).希望你能帮助我
解:
我找到了解决方案.首先,我将NSDate保存在内
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//save date
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] setObject:NSDate.date forKey:@"date"];
[defaults synchronize];
}
Run Code Online (Sandbox Code Playgroud)
然后,当我在应用程序内部返回时,我将保存的日期与实际日期进行比较.如果时间间隔大于5分钟.该应用程序转到密码viewcontroller,强制用户再次登录!
- (void)applicationDidBecomeActive:(UIApplication *)application
{
//calculate difference in time
NSDate *time = [[NSUserDefaults standardUserDefaults] objectForKey:@"date"];
NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:time];
if(timeInterval >= 300){
Password *vc = [[Password alloc] init];
self.window.rootViewController = vc;
[vc release];
[self.window makeKeyAndVisible];
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个UIImage作为截图生成.我正在使用以下代码添加此对象:
self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.0];
drawImage.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.0];
UIGraphicsBeginImageContext(self.view.bounds.size);
[drawImage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef rawImageRef=viewImage.CGImage;
const float colorMasking[6] = {255,255,255,255,0,0};
CGImageCreateWithMaskingColors(rawImageRef, colorMasking);
UIImage *newImage = [UIImage imageWithCGImage:rawImageRef];
Run Code Online (Sandbox Code Playgroud)
然而,我的图像只变白了,我想通过使用CGImageCreateMaskingColors让图像在白色的地方透明.
希望有人可以帮助我.
我正在使用UIImagePickerController将照片中的图片设置为UIImageView.然而,在UIImageView中,图像会自动缩放,因为我在IB中提到了"缩放以适应".我想以80x80像素的分辨率保存我选择的图像,这样我就不必进行缩放.(由于这个扩展问题,我的应用程序变得非常缓慢.)
这是我的代码中的一个snippit:
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
photoView.image = image;
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/foto1.png",docDir];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data writeToFile:pngFilePath atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助!
iphone ×7
image ×2
uiimage ×2
android ×1
facebook ×1
filter ×1
game-center ×1
gdk ×1
google-glass ×1
ios ×1
ios6 ×1
iphone-5 ×1
leaderboard ×1
masking ×1
scale ×1
scroll ×1
tesseract ×1
timer ×1
transparent ×1
uiimageview ×1
xcode ×1
xcode4.5 ×1