我想禁用应用程序中的长触摸.我无法控制我在WebView上加载的HTML.
在每个应用程序中
总是写成[window makeKeyAndVisible];
makeKey是什么意思?
我想在我的应用程序的右下角有一个持久性按钮.在所有视图过渡期间,按钮应保持静态.我在确定添加按钮的视图时遇到问题.我知道按钮应该存储在AppDelegate中,但我不知道除了窗口之外添加它的其他视图是什么意思.将其添加到窗口的一个缺点是,当在后台运行应用程序(即电话)时,添加的状态栏填充将按下窗口.一般来说,将它添加到窗口似乎是一个hacky解决方案 - 任何想法?
我想在UIView的子类上面添加一个广告单元RCTRootView.这将RCTRootView下降约50px.这是我目前的尝试.
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"test"
launchOptions:launchOptions];
CGRect frame = rootView.frame;
frame.size.height -= 50;
rootView.frame = frame;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.autoresizesSubviews = YES;
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
Run Code Online (Sandbox Code Playgroud)
这是一个React Native项目,所以使用了StoryBoard.如何调整rootView的大小?
如何在UIView(广告单元)上方的UIWindow中实例化和附加viewController?
我有一个空的应用程序,没有涉及故事板或xib.我希望有一个隐藏的状态栏,只支持横向.同样,我不想仅在代码中进行这些更改,也不要触摸Info.plist.
我创建了一个带控制器的UIWindow,它表示唯一支持的方向是landscape.在这种情况下,我的UIWindow是在纵向模式的维度中创建的,不会旋转.预期结果将是完全青色的屏幕.

这是我的代表:
#import "AppDelegate.h"
#import "AppViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor cyanColor];
self.window.rootViewController = [[AppViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
@end
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
#import "AppViewController.h"
@implementation AppViewController
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
Run Code Online (Sandbox Code Playgroud)
如果我在调用makeKeyAndVisible之后设置了rootViewController,那么一切似乎都起作用.
self.window.backgroundColor = [UIColor cyanColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[AppViewController alloc] init]; …Run Code Online (Sandbox Code Playgroud) 将视图控制器分配给此属性(以编程方式或使用Interface Builder)将视图控制器的视图安装为窗口的内容视图.
以上引用来自UIWindow的参考.我的问题是关于特定的阶段:
"将视图控制器的视图安装为窗口的内容视图"
确切的内容视图是指什么?
使用Xcode 4.2.1 iPad iOS 5.0.1,创建一个新的"单视图"iPad项目.在控制器中,添加:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void) dumpView: (UIView *) view {
CGRect frame = view.frame ;
CGRect bounds = view.bounds ;
CGPoint center = view.center ;
NSLog(@"view [%@]:%d frame=%@ bounds=%@ center=%@"
, NSStringFromClass(view.class)
, [view hash]
, NSStringFromCGRect(frame)
, NSStringFromCGRect(bounds)
, NSStringFromCGPoint(center)) ;
}
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {
NSLog(@"INViewController.didRotateFromInterfaceOrientation: %d to %d", fromInterfaceOrientation, self.interfaceOrientation) ;
[self dumpView: self.view] ;
[self dumpView: self.view.superview] ;
}
Run Code Online (Sandbox Code Playgroud)
运行它,旋转设备,你会得到:
INViewController.didRotateFromInterfaceOrientation: 2 to 4
view [UIView] bounds={{0, …Run Code Online (Sandbox Code Playgroud) 我正在显示一个UIWindow UIStatusBar,默认UIStatusBarStyle设置为UIStatusBarStyleLightContent,但是当我UIWindow将UIStatusBarStyle开关显示为黑色样式时.
将您的应用程序置于横向模式并执行以下代码:
UIWindow *toastWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
toastWindow.hidden = NO;
toastWindow.backgroundColor = [[UIColor cyanColor] colorWithAlphaComponent:0.5f];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[toastWindow removeFromSuperview];
});
Run Code Online (Sandbox Code Playgroud)
在iOS 7中,您将在整个屏幕上方获得透明的蓝色覆盖,并在5秒后消失.在iOS 8中,您将获得一个透明的蓝色覆盖,覆盖了一半以上的屏幕

这显然与Apple在iOS 8中所做的改变有关,其中屏幕坐标现在面向接口而不是面向设备,但在真正的Apple时尚中,它们似乎在横向模式和旋转方面留下了无数的错误.
我可以通过检查设备方向是否为横向并翻转主屏幕边界的宽度和高度来"修复"这一点,但这似乎是一个可怕的黑客攻击,当Apple在iOS 9中再次更改所有内容时将会破坏.
CGRect frame = [[UIScreen mainScreen] bounds];
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
frame.size.width = frame.size.height;
frame.size.height = [[UIScreen mainScreen] bounds].size.width;
}
UIWindow *toastWindow = [[UIWindow alloc] initWithFrame:frame];
toastWindow.hidden = NO;
toastWindow.backgroundColor = [[UIColor cyanColor] colorWithAlphaComponent:0.5f];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[toastWindow removeFromSuperview];
});
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个问题,遇到了更好,更不易解决的问题?
编辑:我知道我可以使用UIView并将其添加到关键窗口,但我想在状态栏上放置一些东西.
我正在升级应用程序以使用UISceneiOS 13中定义的新模式,但是该应用程序的关键部分已停止工作。我一直在使用a UIWindow来覆盖屏幕上的当前内容并向用户显示新信息,但是在我正在使用的当前Beta(iOS + XCode beta 3)中,该窗口会出现,但随后会立即消失。
这是我正在使用的代码,现在无法使用:
let window = UIWindow(frame: UIScreen.main.bounds)
let viewController = UIViewController()
viewController.view.backgroundColor = .clear
window.rootViewController = viewController
window.windowLevel = UIWindow.Level.statusBar + 1
window.makeKeyAndVisible()
viewController.present(self, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了许多方法,包括使用WindowScenes来呈现新内容UIWindow,但是找不到任何实际的文档或示例。
我的尝试之一(没有用-窗口出现并立即消失的相同行为)
let windowScene = UIApplication.shared.connectedScenes.first
if let windowScene = windowScene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
let viewController = UIViewController()
viewController.view.backgroundColor = .clear
window.rootViewController = viewController
window.windowLevel = UIWindow.Level.statusBar + 1
window.makeKeyAndVisible()
viewController.present(self, animated: true, completion: …Run Code Online (Sandbox Code Playgroud) uiwindow ×10
ios ×8
iphone ×3
objective-c ×3
uiview ×3
cocoa-touch ×2
ios13 ×1
ios8 ×1
landscape ×1
react-native ×1
rotation ×1
swift ×1
uikit ×1
uistatusbar ×1
uiwebview ×1
xcode ×1