微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > iOS 7: 隐藏的特性和解决之道

iOS 7: 隐藏的特性和解决之道

时间:09-12 来源:互联网 点击:

- (UITableView *)tableView

{

return self.originalTableView ?: [super tableView];

}

- (void)searchDisplayController:(UISearchDisplayController *)controller

didShowSearchResultsTableView:(UITableView *)tableView

{

// HACK: iOS 7 requires a cruel workaround to show the search table view.

if (PSPDFIsUIKitFlatMode()) {

if (!self.originalTableView) self.originalTableView = self.tableView;

self.view = controller.searchResultsTableView;

controller.searchResultsTableView.contentInset = UIEdgeInsetsZero; // Remove 64 pixel gap

}

}

- (void)searchDisplayController:(UISearchDisplayController *)controller

didHideSearchResultsTableView:(UITableView *)tableView

{

[self restoreOriginalTableView];

}

这里,别忘了在viewWillDisappear中调用restoreOriginalTableView,否则会发送crash。

记住这是唯一的解决办法;可能有不少激进的方法不替换视图本身,但这个问题确实应该由苹果公司来修复。(TODO: RADAR!)

分页

UIWebView 使用了新的技巧来自动分页带paginationMode的网站。有一大堆与此功能相关的新属性:

@property (nonatomic) UIWebPaginationMode paginationMode NS_AVAILABLE_IOS(7_0);

@property (nonatomic) UIWebPaginationBreakingMode paginationBreakingMode NS_AVAILABLE_IOS(7_0);

@property (nonatomic) CGFloat pageLength NS_AVAILABLE_IOS(7_0);

@property (nonatomic) CGFloat gapBetweenPages NS_AVAILABLE_IOS(7_0);

@property (nonatomic, readonly) NSUInteger pageCount NS_AVAILABLE_IOS(7_0);

现在而言,虽然这可能并非对于大多数网站都有用,但它肯定是生成简单的电子书阅读器或显示文本的一种更好的方式。加点乐子的话,请尝试将它设置为UIWebPaginationModeBottomToTop。

会飞的 Popovers

想知道为什么你的popovers疯了一样到处乱飞?在UIPopoverControllerDelegate协议中有一个新的代理方法使你能控制它:

(void)popoverController:(UIPopoverController *)popoverController

willRepositionPopoverToRect:(inout CGRect *)rect

inView:(inout UIView **)view

当popover锚点是指向一个UIBarButtonItem时,UIPopoverController会有一些动作,但如果你让它在一个view或者rect中显示,你可能就需要实现此方法并正常返回。一个花费了我相当长的时间来验证的问题——如果你通过改变preferredContentSize来动态调整你的popovers,那么这个方法就特别要求得以实现。苹果公司现在对改变popovers大小的请求更严格,如果没有预留足够的空间,popover将会到处移动。

键盘支持

苹果公司不只为我们提供了全新的framework用于游戏控制器,它也给了我们这些键盘爱好者一些提示!你会发现新定义的公用键像 UIKeyInputEscape 或 UIKeyInputUpArrow,可以使用所有新的 UIKeyCommand 类截查。在 iOS7 之前,只能通过一些难以言表的手段来处理键盘命令,现在,就让我们操起蓝牙键盘试试看我们能用这个做什么!

开始之前,你需要对责任者链有个了解。你的 UIApplication 继承自 UIResponder,UIView 和 UIViewController 也是如此。如果你处理过 UIMenuItem 并且没有使用我的基于块的包装的话,那么你已经了解了这些。事件先被发送到最上层的响应者,然后一级级往下传递直到 UIApplication 。为了捕获按键命令,你需要告诉系统你关心哪些键命令(而不是全捕获)。为了完成这个,你需要重写keyCommands这个新属性:

(NSArray *)keyCommands

{

return @[[UIKeyCommand keyCommandWithInput:@f

modifierFlags:UIKeyModifierCommand

action:@selector(searchKeyPressed:)]];

}

- (void)searchKeyPressed:(UIKeyCommand *)keyCommand

{

// Respond to the event

}

现在可别太激动,需要注意的是,这个方法只在键盘可见时有效(比如有类似 UITextView 这样的对象作为第一响应者时)。对于全局热键,你仍然需要用上面的方法。除却那些,这个路径还是很优雅的。不要覆盖类似 cmd-V 系统的快捷键,它会被自动映射为粘贴功能。

还有一些新的预定义的响应行为如:

1

2- (void)increaseSize:(id)sender NS_AVAILABLE_IOS(7_0);

- (void)decreaseSize:(id)sender NS_AVAILABLE_IOS(7_0);

它们分别对应着 cmd+ 和 cmd- 命令,用来放大/缩小内容。

匹配键盘背景

苹果公司终于公开了 UIInputView,其中提供了一种方式——使用UIInputViewStyleKeyb

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top