Tag: cocoa touch

在旋转界面方向的同时将contentOffset保留在UICollectionView中

我正在尝试处理UICollectionViewController中的界面方向更改。 我试图实现的是,我想有一个接口旋转后相同的 contentOffset。 意思是说,它应该根据边界比率的变化而改变。 从纵向开始,内容偏移量为{ bounds.size.width * 2,0} … …应该导致在横向上的内容偏移{ bounds.size.width * 2,0}(反之亦然)。 计算新的偏移量不是问题,但不知道在哪里(或何时)设置它,以获得平滑的animation。 我正在做这样的票价是无效的willRotateToInterfaceOrientation:duration:并重置didRotateFromInterfaceOrientation:的内容偏移didRotateFromInterfaceOrientation: : – (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; { self.scrollPositionBeforeRotation = CGPointMake(self.collectionView.contentOffset.x / self.collectionView.contentSize.width, self.collectionView.contentOffset.y / self.collectionView.contentSize.height); [self.collectionView.collectionViewLayout invalidateLayout]; } – (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; { CGPoint newContentOffset = CGPointMake(self.scrollPositionBeforeRotation.x * self.collectionView.contentSize.width, self.scrollPositionBeforeRotation.y * self.collectionView.contentSize.height); [self.collectionView newContentOffset animated:YES]; } 这将改变旋转后的内容偏移量。 如何在旋转过程中设置它? 我尝试在willAnimateRotationToInterfaceOrientation:duration:设置新的内容偏移量willAnimateRotationToInterfaceOrientation:duration:但是这会导致一个非常奇怪的行为。 一个例子可以在我的GitHub项目中find 。

带有“Go”button而不是返回的iOS键盘

有没有办法使用“Go”键代替“返回”键的键盘,就像当你访问Safari中的login字段? 我猜这应该是一件小事,但我的search没有任何东西。 🙁 提前致谢。

我应该如何传递一个int到stringWithFormat?

我尝试使用stringWithFormat设置标签的文本属性上的数值,但下面的代码不起作用。 我不能将int转换为NSString。 我期待该方法会知道如何自动将一个int转换为NSString。 我需要在这里做什么? – (IBAction) increment: (id) sender { int count = 1; label.text = [NSString stringWithFormat:@"%@", count]; }

找出窗口中的UIBarButtonItem框架?

UIBarButtonItem不扩展UIView ,所以没有什么像框架属性。 但是,有什么办法可以得到什么是CGRect框架,相对于应用程序UIWindow ?

移动UITabBarItem图像?

通常在UITabBar每个选项卡上,都有一个小图像和一个标题来命名选项卡。 图像位于标签顶部的中心位置,以容纳下方的标题。 我的问题是: 如果你想有一个只有一个图像,没有标题的tabBar是否有办法将图像向下移动,以便它在标签中更好? 我正在使用(见下文)目前: [tabBarItem setFinishedSelectedImage:tabSelected withFinishedUnselectedImage:tabUnselected]; 但宁愿使用更大的图像没有标题,现在,如果我使图像大于70像素@ 2x它开始削弱UITabBar的顶部,同时留下很多未使用的空间在底部。

从UITableViewCell引用到父UITableView?

有没有办法从UITableViewCell访问拥有的UITableViewCell ?

如何重新加载和animation只有一个UITableView单元格/行?

我怎样才能重新加载和animation只有一个单元格/行? 现在我下载一些文件。 每次文件完成下载,我称之为完成委托,并调用[tableview重载]。 但是整个桌子重新加载。 我怎么能animation表,以便它不闪烁,例如淡入淡出效果。 问候最大

相当于-respondsToSelector的类方法:

是否有一个类的方法等价于-respondsToSelector: 像+respondsToSelector: 我问的原因是因为通过实现-respondsToSelector:在类级别上,我得到一个编译器警告:“found”-respondsToSelector:“而不是”协议中的“+ respondsToSelector:”。 代码如下所示: Class <SomeProtocol> someClass = [someInstance class]; if ([someClass respondsToSelector:@selector(someSelector:)]) { someVar = [someClass someSelector:someData]; }

如何从UIPickerView获取选定的值

我知道用UIDatePicker,你可以使用像这样的东西: NSDate *myDate = picker.date; 但我在我看来使用UIPickerView。 我怎样才能得到所选的价值? 或者我必须设置didSelectRowtypes的方法来做到这一点? 更新:此代码适用于具有1个组件的选取器: NSInteger row; NSString *weightSelected; row = [repPicker selectedRowInComponent:0]; weightSelected = [pickerArray objectAtIndex:row]; 我厌倦了这个代码,带有两个组件,但它是冻结的: NSInteger row1, row2; NSString *weightSelected1; NSString *weightSelected2; row1 = [repPicker selectedRowInComponent:0]; row2 = [repPicker selectedRowInComponent:1]; weightSelected1 = [pickerArray objectAtIndex:row1]; weightSelected2 = [pickerArray objectAtIndex:row2]; NSString *weightSelected = [NSString stringWithFormat:@"%@.%@", weightSelected1, weightSelected2];

我怎样才能设置一个UITableView分组的风格

我有一个UITableViewController子类的部分。 部分显示为默认样式(不带圆angular)。 我怎样才能设置TableView风格分组的代码? 我没有使用Interface Builder,所以我需要类似的东西 [self.tableView setGroupedStyle] 我search堆栈溢出,但不能拿出一个答案。