- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的项目有一个功能,我已将我的应用程序与投影仪等外部显示器连接起来。我的应用程序在两个方向上都可以工作。我的应用程序中有 2 个窗口。 window1 是我们的默认窗口。我创建了window2,他的名字是外部窗口。我创建了外部窗口,因为我不想在投影仪上显示我的整个应用程序,所以我只是在 window2 上添加 View Controller ,然后在外部显示器(投影仪)上显示 window2。
现在的问题是,当我更改应用程序的方向时,它工作正常,但 window2 不旋转。 Window2 始终以横向模式显示。我只想将 window2 的方向设置为与 window1 相同。我已经尝试了很多但找不到任何解决方案。
请检查我的代码。我添加了如何将应用程序与外部显示器连接的代码。如果我做错了什么,请检查并帮助我。
AppDelegate.m
-(void)initExternalWindow
{
//Setup external screen window
(AppObj).externalWindow = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
(AppObj).externalScreen = [sb instantiateViewControllerWithIdentifier:@"ExternalVC"];
UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:(AppObj).externalScreen];
navController.navigationBarHidden=YES;
(AppObj).externalWindow.opaque = NO;
(AppObj).externalWindow.rootViewController = navController;
(AppObj).externalWindow.backgroundColor = view_bg_color;
(AppObj).externalWindow.hidden = NO;
(AppObj).externalWindow.opaque = NO;
[(AppObj).externalWindow makeKeyAndVisible];
}
ViewController.m
- (void)viewDidLoad {
[self setupScreenConnectionNotificationHandlers];
}
#pragma mark- External dispaly detections (Add Notifications)
- (void)setupScreenConnectionNotificationHandlers
{
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenConnectNotification:(NSNotification*)aNotification
{
[self setupExternalScreen];
}
- (void)handleScreenDisconnectNotification:(NSNotification*)aNotification
{
if ((AppObj).externalWindow)
{
(AppObj).externalWindow.hidden = YES;
(AppObj).externalWindow = nil;
}
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate
{
return YES;
}
外部VC.m
- (void)viewDidLoad {
[super viewDidLoad];
self.updatedImg.image = (AppObj).updatedImg;
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
// UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"];
[UINavigationController attemptRotationToDeviceOrientation];
[UIViewController attemptRotationToDeviceOrientation];
}];
}
最佳答案
在这里,您可以使用旋转窗口,现在您也必须在窗口旋转时旋转图像。按照您的需要进行其他更改,我已经为您提供了一个带有设备旋转的旋转窗口,只需用以下代码替换ExternalVC.m
//
// ExternalVC.m
// Sketch
//
// Created by mac on 21/07/18.
// Copyright © 2018 mac. All rights reserved.
//
#import "ExternalVC.h"
@interface ExternalVC ()
@end
@implementation ExternalVC
- (void)viewDidLoad {
[super viewDidLoad];
self.updatedImg.image = (AppObj).updatedImg;
NSLog(@"External window bounds:%lu",(unsigned long)self.supportedInterfaceOrientations);
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationDidChange:(NSNotification*)aNotification
{
NSLog(@"orientation did change :%@",aNotification);
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// [self transformForOrientation:orientation];
[self.view.window setTransform:[self transformForOrientation:orientation]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
if ([UIScreen mainScreen] == (AppObj).externalWindow.screen || !(AppObj).externalWindow) {
return UIInterfaceOrientationMaskAll;
}else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
// UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
//
// NSLog(@"External window bounds:%f || %f",(AppObj).externalWindow.bounds.size.width,(AppObj).externalWindow.bounds.size.height);
// // UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
// // [(AppObj).externalWindow setValue:@(orientation) forKey:@"orientation"];
//// [[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"];
////
////
//// [UINavigationController attemptRotationToDeviceOrientation];
// [UIViewController attemptRotationToDeviceOrientation];
// UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// [self transformForOrientation:orientation];
}];
}
#define DegreesToRadians(degrees) (degrees * M_PI / 180)
- (CGAffineTransform)transformForOrientation:(UIDeviceOrientation)orientation {
// [self.view.window setFrame:CGRectMake(0, self.view.window.frame.size.height-50, self.view.window.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
// [self.view.window makeKeyAndVisible];
switch (orientation) {
case UIInterfaceOrientationLandscapeLeft:
NSLog(@"UIInterfaceOrientationLandscapeLeft****");
return CGAffineTransformMakeRotation(DegreesToRadians(90));
case UIInterfaceOrientationLandscapeRight:
NSLog(@"UIInterfaceOrientationLandscapeRightt****");
return CGAffineTransformMakeRotation(-DegreesToRadians(90));
case UIInterfaceOrientationPortraitUpsideDown:
NSLog(@"UIInterfaceOrientationUpSideDownPortrait****");
return CGAffineTransformMakeRotation(DegreesToRadians(180));
case UIInterfaceOrientationPortrait:
default:
NSLog(@"UIInterfaceOrientationPortait****");
return CGAffineTransformMakeRotation(DegreesToRadians(0));
}
}
- (void)statusBarDidChangeFrame:(NSNotification *)notification {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSLog(@"status bar orientation :%ld",(long)orientation);
// [self.view setTransform:[self transformForOrientation:orientation]];
}
-(BOOL)shouldAutorotate{
return YES;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
关于ios - 设备方向改变时 UIWindow 不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58027841/
...沮丧。我希望我的游戏仅在横向模式下运行。我已将适当的键/值添加到 Info.plist 文件中,以强制设备方向在启动时正确。 我现在正在尝试旋转 OpenGL 坐标空间以匹配设备的坐标空间。我正
我如何创建一个旋转矩阵,将 X 旋转 a,Y 旋转 b,Z 旋转 c? 我需要公式,除非您使用的是 ardor3d api 的函数/方法。 矩阵是这样设置的 xx, xy, xz, yx, yy, y
假设我有一个包含 3 个 vector 的类(一个用于位置,一个用于缩放,一个用于旋转)我可以使用它们生成一个变换矩阵,该矩阵表示对象在 3D 空间中的位置、旋转和大小。然后我添加对象之间的父/子关系
所以我只是在玩一个小的 javascript 游戏,构建一个 pacman 游戏。你可以在这里看到它:http://codepen.io/acha5066/pen/rOyaPW 不过我对旋转有疑问。你
在我的应用程序中,我有一个 MKMapView,其中显示了多个注释。 map 根据设备的航向旋转。要旋转 map ,请执行以下语句(由方法 locationManager 调用:didUpdateHe
使用此 jquery 插件时:http://code.google.com/p/jqueryrotate/wiki/Documentation我将图像旋转 90 度,无论哪个方向,它们最终都会变得模糊
我有以下代码:CSS: .wrapper { margin:80px auto; width:300px; border:none; } .square { widt
我只想通过小部件的轴移动图像并围绕小部件的中心旋转(就像任何数字绘画软件中的 Canvas ),但它围绕其左顶点旋转...... QPainter p(this); QTransform trans;
我需要先旋转图像,然后再将其加载到 Canvas 中。据我所知,我无法使用 canvas.rotate() 旋转它,因为它会旋转整个场景。 有没有好的JS方法来旋转图片? [不依赖于浏览器的方式] 最
我需要知道我的 Android 设备屏幕何时从一个横向旋转到另一个横向(rotation_90 到 rotation_270)。在我的 Android 服务中,我重新实现了 onConfigurati
**摘要:**本篇文章主要讲解Python调用OpenCV实现图像位移操作、旋转和翻转效果,包括四部分知识:图像缩放、图像旋转、图像翻转、图像平移。 本文分享自华为云社区《[Python图像处理] 六
我只是在玩MTKView中的模板设置;并且,我一直在尝试了解以下内容: 相机的默认位置。 使用MDLMesh和MTKMesh创建基元时的默认位置。 为什么轮换还涉及翻译。 相关代码: matrix_f
我正在尝试使用包 dendexend 创建一个树状图。它创建了非常好的 gg 树状图,但不幸的是,当你把它变成一个“圆圈”时,标签跟不上。我将在下面提供一个示例。 我的距离对象在这里:http://s
我想将一个完整的 ggplot 对象旋转 90°。 我不想使用 coord_flip因为这似乎会干扰 scale="free"和 space="free"使用刻面时。 例如: qplot(as.fac
我目前可以通过首先平移到轴心点然后执行旋转最后平移回原点来围绕轴心点旋转。在我的例子中,我很容易为肩膀做到这一点。但是,我不知道如何为前臂添加绕肘部的旋转。 我已经尝试了以下围绕肘部旋转的前臂: 平移
我想使用此功能旋转然后停止在特定点或角度。现在该元素只是旋转而不停止。代码如下: $(function() { var $elie = $("#bkgimg");
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我正在尝试创建一个非常简单的关键帧动画,其中图形通过给定的中点从一个角度旋转到另一个角度。 (目的是能够通过大于 180 度的 OBTUSE 弧角来制作旋转动画,而不是让动画“作弊”并走最短路线,即通
我需要旋转 NSView 实例的框架,使其宽度变为其高度,其高度变为其宽度。该 View 包含一个字符串,并且该字符串也被旋转,这一点很重要。 我查看了 NSView 的 setFrameRotati
我正在编写一个脚本,用于在 javascript 中旋转/循环浏览图像,同时遵守循环浏览图像的次数限制。我所拥有的如下: var delay = 3000; //6000 = change to
我是一名优秀的程序员,十分优秀!