Tag: 方向

在iMessage应用程序中检查风景/纵向(扩展名)

已经看到很多解决scheme来检查方向,但奇怪的是,没有任何工作! 以下是代码片段, override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { let screenSize = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print("Screen Width = \(screenWidth)") print("Screen Height = \(screenHeight)") if (screenWidth > screenHeight) { print("Landscape") alertView.removeFromSuperview() messageView.addGestureRecognizer(tapTextView) } else { print("Portrait") setupLandscapeAlertView() } } 另一种用来设置视图的方法是, fileprivate func setupLandscapeAlertView() { messageView.removeGestureRecognizer(tapTextView) alertView = UIView(frame: […]

在App使用过程中,cocos2d v3重新定位屏幕

所以在cocos2d(我相信我是在V2.1)我做了这个locking和设置方向: AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; const UIInterfaceOrientation ORIENTATION = delegate.navController.interfaceOrientation; delegate.navController. delegate.navController.screenOrientation = ORIENTATION == UIInterfaceOrientationMaskPortrait; UIViewController *mVC = [[UIViewController alloc] init]; [delegate.navController presentModalViewController:mVC animated:NO]; [delegate.navController dismissModalViewControllerAnimated:NO]; 随着一些function添加到AppDelegate。 我似乎无法在iOS7和cocos2d v3中获得相同的结果。 我已经挖了一下,适当的function似乎已经到位,但似乎无法设置一个全局variables来设置方向,并在特定时间只返回一个我想要的。 有人能指出我的正确道路吗? 我想我错过了一些非常小的东西,因为正确的代码似乎已经在那里了。 这是我的AppDelegate的代码 @implementation AppDelegate -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self setupCocos2dWithOptions:@{ CCSetupShowDebugStats: @(NO), }]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; return YES; } […]

shouldAutorotateToInterfaceOrientation:从来没有调用

我将“支持的界面方向”设置为“部署信息”下除“人像”之外的所有人物。 我想重写shouldAutorotateToInterfaceOrientation:用于自定义行为。 (即根据条件支持景观) 我只有一个视图控制器由于约束(自定义视图转换) 这就是我的appdelegate中的代码: self.viewController = [[MyController alloc]initWithNibName:nil bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; 并在myController.m,我重写shouldAutorotateToInterfaceOrientation: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES; } 应用程序自动转向所有的方向,但倒像和callback从来没有被调用。 我已经尝试了从shouldAutorotateToInterfaceOrientation更改返回的build议:在runTime没有成功。 为什么? 在附注中,在运行时更改旋转支持的最佳方法是什么? 更新: – (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 被调用。 我试过放进去 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 没有成功:(

iOS 6 supportedInterfaceOrientations问题

在我的视图控制器中,我实现了两种控制界面方向的方法: – (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } – (BOOL)shouldAutorotate { return YES; } 在supportedInterfaceOrientations方法中,我返回UIInterfaceOrientationMaskPortrait但是当时我意识到shouldAutorotate方法没有被调用。 但是我更改为在supportedInterfaceOrientations方法中return UIInterfaceOrientationPortrait 。 正在调用shouldAutorotate方法,但是在shouldAutorotate了一个错误: UIApplicationInvalidInterfaceOrientation ,原因:“支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES” 顺便说一下,我select支持的界面方向中的所有方向。 EDITED 我使用viewController和embeddednavigationController。 这里是AppDelegate.h @interface AppDelegate : UIResponder <UIApplicationDelegate,UINavigationControllerDelegate> @property (strong, nonatomic) UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; @property (readonly, strong, […]

如何从纵向模式转换到横向模式并locking它?

我有一个电影视图压缩在肖像模式的右下方视口。 当用户展开电影视图时,电影视图将以横向模式展开为全屏。 无论设备是什么方向,我也想在全屏时将电影视图locking到横向模式。 注意:我所有的其他视图都是以肖像模式。 我用这个代码来引用这个post , 应用设置, AppDelegate.swift internal var shouldRotate = false func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return shouldRotate ? .allButUpsideDown : .portrait } 视图控制器, func expandPlayerWindow(button: UIButton) { self.player.view.frame = CGRect(x:0, y:-20, width: UIScreen.main.bounds.maxY, height: UIScreen.main.bounds.maxX) let appDelegate = UIApplication.shared.delegate as! AppDelegate print(appDelegate.shouldRotate) print(self.supportedInterfaceOrientations) appDelegate.shouldRotate = true // […]

UIPopoverController的位置

我正在开发一个应用程序,这个应用程序应该是通用的,一个用于iPad和iPhone的应用程序。 我想保持它们的接口尽可能相似。 在iPhone应用程序中,我使用了一个选项卡栏控制器,其中一个选项卡会转到图像选取器控制器。 很明显,我不能在iPad上做到这一点。 所以我已经劫持了该button的控制,以带有一个popup在图像select器中的popupcontroller。 这一切都工作得很好,除非我popuppopup窗口,它不是在正确的位置。 当我旋转模拟器,popup去正确的地方,并保持我甚至回转。 我的代码是基于这个问题的代码: Ipad UIImagePickerController和UIPopoverController错误 为什么我的popup不在正确的位置?

iOS MapKit通过道路在地图上连接多个点

我正在使用此代码连接折线上的针脚(地图上的点): CLLocationCoordinate2D coordinates[allLocations.count]; int i = 0; for (locHolder *location in allLocations) { coordinates[i] = CLLocationCoordinate2DMake([location.lat floatValue], [location floatValue]); i++; } MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coordinates count:[allLocations count]]; self->polyline = polyline; [self.mapView addOverlay:self->polyline level:MKOverlayLevelAboveRoads]; 但是这个代码将它们连接在空中(忽略道路),是否有可能将多个CLLocationCoordinate2D位置连接到沿着道路的多段线? **还有一个小问题,[allLocations count]和allLocations.count之间的性能是否有差异? 谢谢。

如何通过平移手势限制可移动的视图

我有一个UIImageView可以通过平移手势移动。 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self.photoMask addGestureRecognizer:pan]; 我想限制可以在屏幕上移动的区域。 而不是用户能够将视图拖到屏幕的一侧,我想限制它的某种边缘。 我怎样才能做到这一点? 另外,这是如何处理时,旋转? 编辑— #pragma mark – Gesture Recognizer -(void)handlePan:(UIPanGestureRecognizer *)gesture { NSLog(@"Pan Gesture"); gesture.view.center = [gesture locationInView:self.view]; } 这是我目前处理泛的方法。 我需要做的是继续移动中心点的图像视图,并限制其靠近屏幕边缘的运动,例如50。

无法lockingiPad Air 2的方向

我正在处理的iOS应用程序有一个视图,需要在横向方向上locking。 到目前为止,这是通过使用shouldAutorotate和supportedInterfaceOrientations方法完成的,但是在运行iOS9 beta5的iPad Air 2上,这些方法永远不会触发,方向也不会被locking。 我尝试了以下设备,除了Air2(运行Xcode beta6运行debugging)之外,所有方法都被触发:iPhone 6+,iPad Mini,iPad Air 2,iPad 2,iPad 3 没有触发的方法如下: – (BOOL)shouldAutorotate { return YES; } – (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } – (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskLandscapeRight; } 视图控制器通过presentViewController显示

iOS 6:将视图控制器推入导航控制器堆栈时如何强制更改方向

我觉得这个问题现在应该已经有一百万次了,但是我还是找不到答案。 这是我的层次结构:UINavigationController – > UIViewController 1 – >(push) – > UIViewController 2 UINavigationController:支持所有可能的方向UIViewController 1:仅支持纵向UIViewController 2:仅支持横向 我怎样才能lockingUIViewController 1到肖像只有同时lockingUIViewController 2到景观只? 这甚至有可能吗? 到目前为止,我所看到的是UIViewController 2总是采用UIViewController 1的方向。 请注意,这仅适用于iOS 6。 谢谢!