Tag: cocoa触摸

在ARC下将对象安全地作为不透明的上下文parameter passing

在手动内存pipe理下,我经常使用这个模式: NSString * myStr = /* some local object */ [UIView beginAnimation:@"foo" context:(void *)[myStr retain]]; 然后,后来和asynchronous: – (void)animationDidStop:(NSString *)anim finished:(NSNumber *)num context:(void *)context { NSString * contextStr = (NSString *)context; // … [contextStr release]; } 即我手动pipe理用作不透明上下文的对象的生命周期。 (对于旧的UIViewanimation,对于其他types的API也是如此。) 在ARC下,我的本能就是我想要__bridge_transfer在处理程序中进入__bridge_transfer , 正如这里所build议的那样 。 但是这把cocoa物体当作CFType并不是因为它是真的桥接的,而仅仅是为了把一个可卡因放在喉咙里。 这是否有效,这在风格上是可以接受的? 如果没有,最好的解决scheme是什么? ( 在这个问题上接受的答案给出了一个不同的答案,说只有__bridge是可以的,但是在我看来是错误的,因为原来的string在第一个__bridge就有可能被释放function,对吗?) *请不要说“改为使用基于块的animation”。 (这不是我问的。)

如何在ReactiveCocoa 4中创build自定义信号?

我有以下设置,一个由GridViewCell组成的GridViewCell 。 网格视图 class GridView : UIView { var gridViewCells: [GridViewCell] = [] let tapHandler: Position -> () init(frame: CGRect, tapHandler: Position -> ()) { self.tapHandler = tapHandler super.init(frame: frame) self.gridViewCells = createCells(self) addCellsToView(self.gridViewCells) } func addCellsToView(cells: [GridViewCell]) { for cell in cells { self.addSubview(cell) } } } GridViewCell class GridViewCell: UIImageView { let position: […]

touchesMoved不定期地调用

我正在制作一款iOS游戏,主要是在屏幕上拖动大对象。 当我在实际的iPad / iPhone上运行游戏一段时间(持续在屏幕上拖动对象的圆圈)时,每隔5分钟左右拖动的对象就会全部结束约10-30秒 。 然后,它回到丝绸般光滑。 从表面上看,游戏的帧速率似乎下降到了15fps,但事实上,它一直在以60fps的速度运行。 不过,我注意到唯一不顺畅的是被拖动的对象 ,而游戏的其余部分都运行得非常顺利。 这让我相信口吃与iOS中的触摸input有关。 所以我开始看touchesMoved,看到它通常每16毫秒调用一次(所以触摸input以60 fps运行)。 到现在为止还挺好。 然后我注意到, 当对象开始口吃时,touchesMoved开始以奇怪的时间间隔被调用,在8毫秒和50毫秒之间波动很大。 所以,当触摸屏处于这种奇怪的状态时,有时touchesMoved会在前一次调用后的8毫秒内被调用,有时直到前一次调用后的50毫秒才会被调用。 当然,这使得被拖动的对象看起来全是断断续续的,因为它的位置是以不规则的间隔更新的。 你有什么想法是什么可能造成触摸移动停止被定期调用,如通常一样? 奖金: – 每当我倾斜屏幕强制屏幕方向改变时,大约70%的时间触摸屏进入上述状态touchesMoved开始被不规则地调用。 然后在10-20秒后恢复正常,再次看起来平滑。 – 我已经在两台iPad和两台iPhone(iOS 6和7)上试过了,这个问题出现在所有这些设备上。 – 使用OpenGLES视图来显示graphics。 它使用CADisplayLink同步到显示刷新率。 – 我用来testing这个的Xcode项目已经由unity3d游戏开发工具生成,但是我发现了几个非统一的游戏出现了相同的问题。 这似乎是一个全系统的问题。 注意我使用CFAbsoluteTimeGetCurrent测量objective-c中的CFAbsoluteTimeGetCurrent ,完全在统一之外。

跟踪时间花在应用程序上

我应该使用什么来追踪用户在iOS设备上使用我的应用程序的时间? 我想我可以这样做: 在App启动时logging时间( application:didFinishLaunchingWithOptions: 在应用程序结束日志时间( applicationWillTerminate: :) 项目清单 向服务器发送报告(开始/结束时间对),并计算在应用中花费的时间 你有什么更好的想法? 重要的是要有效的networking和资源 (不要发送大量数据或在复杂的计算操作上使用iOS资源。)

应用程序只启用肖像,但UIImagePickerController在iOS6中旋转

请注意下面的答案 – 不适用于iOS6,所以我仍然需要一个答案! 我的应用程序仅适用于肖像模式。 但是,如果我内嵌一个UIImagePickerController作为子视图,并旋转设备,顶部和底部酒吧留在相同的位置,但UIImagePickerController不会旋转。 我怎样才能防止它旋转? 这是代码: [self.view.window addSubview:self.imagePickerController.view]; self.imagePickerController.showsCameraControls = NO; self.imagePickerController.view.frame = CGRectMake(0, 90, 320, 320); self.imagePickerController.allowsEditing = NO; EDITED 我正在使用iOS6,其中shouldAutorotate不是calle

我应该为每个标签栏使用单独的UINavigationController

根据苹果 ,我可以结合UINavigationController和UITabBarController使用的代码,例如 MyViewController1* vc1 = [[MyViewController1 alloc] init]; MyViewController2* vc2 = [[MyViewController2 alloc] init]; MyViewController3* vc3 = [[MyViewController3 alloc] init]; MyNavRootViewController* vc4 = [[MyNavRootViewController alloc] init]; UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vc4]; NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, navController, nil]; tabBarController.viewControllers = controllers; 在这个设置中,只有vc4有UINavigationController ,但是如果我想要vc1-vc3也有UINavigationController ?,我应该怎么做? MyViewController1* vc1 = [[MyViewController1 alloc] init]; UINavigationController* nv1 […]

DisclosureIndicator不检测触摸

我使用UITableViewCellAccessoryDisclosureIndicator作为我的UITableViewCell accessoryType 。 根据苹果的文档,数据源的方法 – (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 应该会自动被调用。 如果单元格已启用,并且附件types为UITableViewCellAccessoryDe​​tailDisclosureButton,则附件视图会跟踪触摸,并在轻敲时向数据源对象发送tableView:accessoryButtonTappedForRowWithIndexPath:消息。 这是我的代码: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } [cell.textLabel setText:[datasource objectAtIndex:indexPath.row]]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } 数据源方法只是一个NSLog但没有打印… 我错过了什么吗? (当然,数据源和代理设置正确)

applicationDidFinishLaunching:是否在第一次更新和启动应用程序时被调用?

applicationDidFinishLaunching保证在应用程序更新后被调用吗? (当用户第一次启动更新的版本。) 换句话说,如果在更新过程中以后台模式运行,旧版本会被杀死?

避免UIImage的imageNamed – 内存pipe理

我正在通过这个链接,我碰到一个点避免UIImage的imageNamed 。 为什么我们应该避免这个? 谢谢, 尼蒂什

leftbarbuttonitem不显示在导航栏中

我一直在开发一个iOS应用程序,并一直在使用图像作为导航栏中的左栏button项的问题。 我尝试了以下方法: UIImage *backButtonImage = [UIImage imageNamed:@"backbuttonCB"]; CGRect buttonFrame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height); UIButton *backButton = [[UIButton alloc] initWithFrame:buttonFrame]; [backButton setImage:backButtonImage forState:UIControlStateNormal]; UIBarButtonItem *backBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView: backButton]; self.navigationItem.leftBarButtonItem = backBarButtonItem; 酒吧button似乎永远不会显示在运行应用程序。 然后,我继续尝试下面的其他方法。 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backbuttonCB"] style:UIBarButtonItemStylePlain target:nil action:@selector(methodname)]; 这个方法实际上工作。 然而,显示的图像是蓝色的,看起来不像是这个意思。 改变这个图像的色调并没有帮助。 任何想法如何我可以解决这个问题? 编辑:更多的信息,如果有帮助。 这是导航堆栈中的第一个视图。 导航堆栈以模态方式显示,即存在先前的视图控制器,并且在先前的视图控制器和导航控制器之间存在模态延续。 这是导航堆栈中的第一个视图。 编辑:问题是固定的。 我认为这是一个在Xcode中的错误,因为当我重新启动Xcode并用实际的设备而不是模拟器testing它,它工作正常。 但是,似乎仍然不能在仿真器上工作。