我正在Swift 2中构建一个闹钟应用程序.我似乎无法找到一个合适的方法来确定手机是否设置为24小时.另外我无法将模拟器更改为24小时工作,所以我甚至无法通过播放时间设置来测试一些替代方案.有任何想法吗?
我正在调整一个应用程序来支持iPhone X.我有一个自定义视图控制器的共享扩展.我需要知道我的设备的安全区域插入,但是通过调用提供的safeAreaInsets方法在共享扩展中不可用,因为在那里不可见.有没有办法知道我的共享扩展中的属性值?UIWindowUIApplication.shared.keyWindowUIApplication.sharedsafeAreaInsets
我正在使用UINavigationController来显示一些视图控制器。每次在两个视图控制器之间切换时,都需要更改导航栏标题的颜色。这就是我现在正在做的:
第一视图控制器
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
}
Run Code Online (Sandbox Code Playgroud)
第二视图控制器
- (void)viewDidLoad:(BOOL)animated
{
[super viewDidLoad:animated];
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor blackColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
}
Run Code Online (Sandbox Code Playgroud)
第一次加载First VC时,当我按Second VC时,标题颜色已正确处理。这里的问题是,当我从第二个视图控制器弹出到第一个视图控制器时,即使viewWillAppear调用正确,标题仍然是黑色的,并且如果我打印self.navigationController.navigationBar.titleTextAttributes,值似乎也已更新(NSForegroundColorAttributeName是白色的)。
我想显示UIAlertController上的顶部UIViewController有一个UICollectionView内.集合视图需要专注于启动,所以我preferredFocusableView按如下方式覆盖变量:
override var preferredFocusedView: UIView? {
return self.collectionView
}
Run Code Online (Sandbox Code Playgroud)
使用tvOS 9一切正常:警报控制器正常打开,我可以选择其中一个UIAlertAction显示的.
在tvOS 10 Golden Master上,打开警报控制器并滚动到另一个动作后,焦点从屏幕上消失,我无法滚动到其他操作或点击Siri遥控器的菜单按钮.该应用程序仍然卡在警报控制器中,当我尝试滚动到其他操作但屏幕上没有任何操作时,我可以听到滚动声音.我必须强制退出应用程序并重新打开它.
这是应用程序的代码.我尝试设置preferredFocusableViewto alertController.preferredFocusedView或删除集合视图的焦点方法,但没有结果.
var alertController : UIAlertController?
func showAlert() {
alertController = UIAlertController(title:"Example title", message: "Example description", preferredStyle: .Alert)
let action1 = UIAlertAction(title: "Option 1", style: .Default) { (action : UIAlertAction) -> Void in
//call to another method
}
// action2, action3, action4...
let action5 = UIAlertAction(title: "Option 5", style: .Default) { (action …Run Code Online (Sandbox Code Playgroud) 我需要使用a QLPreviewController才能在我的应用程序中打开PDF和JPEG文档.我用这种方式实现了它:
-(void)openQuickLook{
QLPreviewController *preview = [[QLPreviewController alloc] init];
preview.currentPreviewItemIndex = 0;
preview.delegate = self;
preview.dataSource = self;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:preview];
[self presentViewController:nav animated:YES completion:nil];
}
#pragma mark - Quicklook
-(NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller{
return photos.count;
}
-(id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index{
return photos[index];
}
Run Code Online (Sandbox Code Playgroud)
当我调用该openQuickLook方法时,预览控制器显示带有编辑工具的底栏 - 类似于iOS"标记"功能.这仅在JPEG文件上发生.酒吧固定在屏幕上; 我可以选择颜色和尺寸,但我不能在图像上画任何东西.
我需要从预览视图控制器中删除此栏,但我还没有在网上找到有关此功能的任何内容.
我在Kotlin写一个应用程序.我有一个来自Web服务的原始JSON字符串,我需要将它与Gson一起使用.
我这样做:
val gson = Gson()
val friends = gson.fromJson(response.rawResponse, JsonElement::class)
Run Code Online (Sandbox Code Playgroud)
但编译器无法找到正确的fromJson方法重载,而目前可用的是(fromJson(json: String!, typeOfT: Type!)).
这是错误:
Error:(65, 50) None of the following functions can be called with the arguments supplied:
public open fun <T : Any!> fromJson(json: JsonElement!, classOfT: Class<JsonElement!>!): JsonElement! defined in com.google.gson.Gson
public open fun <T : Any!> fromJson(json: JsonElement!, typeOfT: Type!): JsonElement! defined in com.google.gson.Gson
public open fun <T : Any!> fromJson(reader: JsonReader!, typeOfT: Type!): JsonElement! defined in com.google.gson.Gson
public open fun <T …Run Code Online (Sandbox Code Playgroud)