vida util real precio plus original duracion dura cuanto bateria iphone ios uiinterfaceorientation uidevice

util - iphone 6 duracion real bateria



iOS: orientaciĆ³n del dispositivo en carga (16)

Creo que esto funcionará:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;

Según la referencia del dispositivo UID:
Citar:
"El valor de esta propiedad siempre devuelve 0 a menos que las notificaciones de orientación se hayan habilitado llamando a beginGeneratingDeviceOrientationNotifications"
Inicialmente había asumido que esta propiedad contenía la orientación actual en todo momento, pero aparentemente no. Supongo que las notificaciones se están gestionando detrás de nosotros en otras situaciones en las que normalmente se accede a la propiedad de orientación, por lo que no era obvio que esto debe hacerse manualmente dentro del delegado de la aplicación

Parece que cuando se carga mi aplicación, no conoce su orientación actual:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; if (orientation == UIDeviceOrientationPortrait) { NSLog(@"portrait");// only works after a rotation, not on loading app }

Una vez que giro el dispositivo, obtengo una orientación correcta, pero cuando cargo la aplicación, sin cambiar la orientación, parece que al usar [[UIDevice currentDevice] orientation] no se conoce la orientación actual.

¿Hay otra forma de verificar esto cuando cargue mi aplicación por primera vez?


En la carga, la orientación del dispositivo puede ser .Unknown o .FaceUp . Para averiguar si es vertical u horizontal, utilizo el statusBarOrientation como una copia de seguridad, como esto:

var portraitOrientation = UIDevice.currentDevice().orientation == .Portrait if UIDevice.currentDevice().orientation == .Unknown || UIDevice.currentDevice().orientation == .FaceUp { portraitOrientation = UIApplication.sharedApplication().statusBarOrientation == .Portrait }

De esta manera puedo asegurar que la orientación portraitOrientation siempre me dice si el dispositivo está en modo vertical, y si no, estará en horizontal. Incluso al cargar la aplicación por primera vez.


Esta es la respuesta real. Cuando una aplicación se inicia, su orientación es desconocida. Utiliza shouldAutorotateToInterfaceOrientation y supportInterfaceOrientations para decidir qué orientación elegir.

Observe cómo inicio una aplicación de muestra en el simulador de iPhone 5.0 y gírela usando el código a continuación y las ''Orientaciones de interfaz admitidas'' con las 4 orientaciones posibles:

20:44:08.218 RotationTestApp Supported orientation: Portrait 20:44:08.222 RotationTestApp Supported orientation: Portrait (upside-down) 20:44:08.225 RotationTestApp Supported orientation: Landscape (home button on the right) 20:44:08.225 RotationTestApp Supported orientation: Landscape (home button on the left) 20:44:08.226 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (current device orientation: UIDeviceOrientationUnknown, interface orientation wants: UIInterfaceOrientationPortrait) 20:44:08.237 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (current device orientation: UIDeviceOrientationUnknown, interface orientation wants: UIInterfaceOrientationPortrait) 20:44:08.239 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (current device orientation: UIDeviceOrientationUnknown, interface orientation wants: UIInterfaceOrientationPortrait) 20:44:08.240 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (current device orientation: UIDeviceOrientationUnknown, interface orientation wants: UIInterfaceOrientationPortrait) 20:44:09.817 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationLandscapeLeft) 20:44:09.833 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationLandscapeLeft) 20:44:11.030 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationPortraitUpsideDown) 20:44:11.040 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationPortraitUpsideDown) 20:44:12.599 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationLandscapeRight) 20:44:12.609 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationLandscapeRight) 20:44:13.301 RotationTestApp shouldAutorotateToInterfaceOrientation: YES (device orientation: UIDeviceOrientationPortraitUpsideDown)

He visto muchos fragmentos de código, pero ninguno de ellos funciona lo suficientemente genérico (iPad y iPhone, iOS 5.0+).

En lugar de buscar a tientas con try-this-try-that, coloca lo siguiente en tu raíz vc:

#define ToNSString_BEGIN(T) / NSString* T##ToNSString(T valueParameter) { / switch (valueParameter) { #define ToNSString_VALUE(value) / case value: return @#value #define ToNSString_END(T) / } / return @"(unknown)"; / } // NSString* UIInterfaceOrientationToNSString(UIInterfaceOrientation); ToNSString_BEGIN(UIInterfaceOrientation); ToNSString_VALUE(UIInterfaceOrientationPortrait); // 1 ToNSString_VALUE(UIInterfaceOrientationPortraitUpsideDown); // 2 ToNSString_VALUE(UIInterfaceOrientationLandscapeLeft); // 3 ToNSString_VALUE(UIInterfaceOrientationLandscapeRight); // 4 ToNSString_END (UIInterfaceOrientation); // NSString* UIDeviceOrientationToNSString(UIDeviceOrientation); ToNSString_BEGIN(UIDeviceOrientation); ToNSString_VALUE(UIDeviceOrientationUnknown); // 0 ToNSString_VALUE(UIDeviceOrientationPortrait); // 1 ToNSString_VALUE(UIDeviceOrientationPortraitUpsideDown); // 2 ToNSString_VALUE(UIDeviceOrientationLandscapeLeft); // 3 ToNSString_VALUE(UIDeviceOrientationLandscapeRight); // 4 ToNSString_VALUE(UIDeviceOrientationFaceUp); // 5 ToNSString_VALUE(UIDeviceOrientationFaceDown); // 6 ToNSString_END (UIDeviceOrientation); // Change this custom method to alter auto-rotation behavior on all supported iOS versions and platforms. - (BOOL)allowAutoRotate:(UIInterfaceOrientation)interfaceOrientation { NSUInteger interfaceOrientationAsMask = (1<<interfaceOrientation); return interfaceOrientationAsMask & [self supportedInterfaceOrientations]; } // Reads from the project''s-Info.plist - (NSUInteger)supportedInterfaceOrientations { static NSUInteger orientationsResult; if (!orientationsResult) { NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"]; for (id orientationString in supportedOrientations) { if ([orientationString isEqualToString:@"UIInterfaceOrientationPortrait"]) { orientationsResult |= UIInterfaceOrientationMaskPortrait; NSLog(@"Supported orientation: Portrait"); } else if ([orientationString isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) { orientationsResult |= UIInterfaceOrientationMaskPortraitUpsideDown; NSLog(@"Supported orientation: Portrait (upside-down)"); } else if ([orientationString isEqualToString:@"UIInterfaceOrientationLandscapeRight"]) { orientationsResult |= UIInterfaceOrientationMaskLandscapeRight; NSLog(@"Supported orientation: Landscape (home button on the left)"); } else if ([orientationString isEqualToString:@"UIInterfaceOrientationLandscapeLeft"]) { orientationsResult |= UIInterfaceOrientationMaskLandscapeLeft; NSLog(@"Supported orientation: Landscape (home button on the right)"); } else { NSLog(@"Unrecognized orientation ''%@'' in mainBundle plist, key UISupportedInterfaceOrientations", orientationString); } } } return orientationsResult; } // iOS 6+ (not yet used in 6.0.1) - (BOOL)shouldAutorotate { UIDeviceOrientation interfaceOrientationFromDevice = [UIDevice currentDevice].orientation; BOOL result = [self allowAutoRotate:interfaceOrientationFromDevice]; NSString *currentDeviceOrientation = UIDeviceOrientationToNSString(interfaceOrientationFromDevice); NSLog(@"shouldAutorotate: %s (current orientation %@)", result ? "YES" : "NO", currentDeviceOrientation); return result; } // iOS 2.0 - 5.1 (iOS 6+ deprecated, 6.0.1 still works) - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { NSString* orientationString; UIDeviceOrientation interfaceOrientationFromDevice = [UIDevice currentDevice].orientation; if ((int)interfaceOrientation != (int)interfaceOrientationFromDevice) { orientationString = [NSString stringWithFormat:@"current device orientation: %@, interface orientation wants: %@", UIDeviceOrientationToNSString(interfaceOrientationFromDevice), UIInterfaceOrientationToNSString(interfaceOrientation) ]; } else { orientationString = [NSString stringWithFormat:@"device orientation: %@", UIDeviceOrientationToNSString(interfaceOrientationFromDevice) ]; } BOOL result = [self allowAutoRotate:interfaceOrientation]; NSLog(@"shouldAutorotateToInterfaceOrientation: %s (%@)", result ? "YES" : "NO", orientationString); return result; }

Todavía hay un problema molesto de las animaciones segue que no utilizan la orientación actual. Mi conjetura es que la subclasificación de cada VC y poner cierta orientación en el delegado de inserción / notificación en el pop sería el camino a seguir.

También es importante:

shouldAutorotateToInterfaceOrientación no funciona

tabBarController y navigationControllers en modo horizontal, episodio II


Intenté todo y no hubo buenos resultados. Entonces, lo que hice, ya que estoy en un ipad, fue dejar todo el trabajo a los métodos splitViewController para invalidar el barButton:

Para el retrato:

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc { NSlog(@"portrait");}

Para el paisaje:

- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem{ NSlog(@"landscape");}

esto siempre funciona en carga.


Para obtener la orientación de la barra de estado, también es importante tener todas las orientaciones habilitadas en el archivo plist.


Prueba este. es un trabajo para mi Gnarly en ese momento del método de lanzamiento finalizado no detectó la orientación del dispositivo. su toma por defecto como un retrato. asi que. Estoy usando para comprobar la orientación de la barra de estadísticas. pruebo este código Póngalo en el método didfinishedlaunch en appdeleget.

UIInterfaceOrientation orientación = [UIApplication sharedApplication] .statusBarOrientation;

if(orientation == 0) {//Default orientation //UI is in Default (Portrait) -- this is really a just a failsafe. NSLog("for portrait"); }else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { NSLog("portrait"); }else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { NSLog("Landscap"); }


Pruebe el acelerómetro para obtener su lectura, UIAccelerómetro, comparta el Acelerómetro, establezca su delegado, obtenga las lecturas, determine la orientación desde allí.


Pruebe este [[UIApplication sharedApplication] statusBarOrientation];

o implementar este en la aplicación delegado

(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; }

funciona


Puedes hacerlo insertando la siguiente notificación en el interior.

-(void)viewDidLoad [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkRotation:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

luego coloca el siguiente método dentro de tu clase

-(void)checkRotation:(NSNotification*)notification { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { //Do your textField animation here } }

El método anterior verificará la orientación de la barra de estado del ipad o iPhone y, de acuerdo con ello, realizará la animación en la orientación requerida.


Todavía utilizo este fragmento de código de trabajo para el iPhone 4:

-(void)deviceOrientationDidChange:(NSNotification *)notification{ //Obtaining the current device orientation UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; int value = 0; if(orientation == UIDeviceOrientationPortrait) { value = 0; }else if(orientation == UIDeviceOrientationLandscapeLeft) { value = 90; }else if(orientation == UIDeviceOrientationLandscapeRight) { value = -90; } CGAffineTransform cgCTM = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(value)); [photoImageView setTransform:cgCTM];

}


Todos los que aparecen arriba publicaron respuestas muy válidas: pero como ACTUALIZACIÓN: la versión de Apple: debe utilizar las orientaciones de UIStatusBar para leer la orientación actual del dispositivo:

Una forma de verificar la orientación actual del dispositivo es mediante el uso de valores int como tales, dentro del método viewDidLoad :

int orientationType = [[UIDevice currentDevice] orientation];

donde considere lo siguiente. . . - 1 = retrato (hacia arriba) - 2 = retrato hacia abajo - 3 = paisaje (derecha) - 4 = paisaje (izquierda)

y luego podría usar una instrucción IF para llamar a un método después de que se detecte la orientación, y así sucesivamente:

Espero que esto haya sido de alguna ayuda para alguien.


Una cosa que nadie ha tocado aún es que está almacenando tipos de UIDeviceOrientation en una variable UIInterfaceOrientation . Son diferentes, y no deben ser tratados como iguales. Tenga en cuenta que UIDeviceOrientationLeft es igual a UIInterfaceOrientationRight (ya que la interfaz gira en sentido opuesto en comparación con el dispositivo).


el problema es que la [UIDevice currentDevice]orientation] veces informa la orientación del dispositivo de forma incorrecta.

en su lugar, use [[UIApplication sharedApplication]statusBarOrientation] que es una UIInterfaceOrientation así que para verificarlo, necesitará usar UIInterfaceOrientationIsLandscape(orientation)

espero que esto ayude.


para aquellos que buscan respuesta para Swift 3 o 4. simplemente agregue ese código dentro del bloque viewDidLoad ().

`let orientation = UIApplication.shared.statusBarOrientation if orientation == .portrait { // portrait } else if orientation == .landscapeRight || orientation == .landscapeLeft{ // landscape }`


EDITAR: He leído mal su pregunta. Esto le permitirá iniciar su aplicación en ciertas orientaciones. Acabo de darme cuenta de que estás intentando averiguar la orientación en el lanzamiento.

Existe un método para verificar la orientación de la barra de estado en UIApplication :

[[UIApplication sharedApplication] statusBarOrientation];

Respuesta original

Intente configurar las orientaciones de dispositivo aceptadas de la aplicación en el archivo plist:

<key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array>

Esto indicará que su aplicación es compatible con Vertical (botón de inicio en la parte inferior), horizontal izquierda y horizontal derecha.

Luego, en sus UIViewControllers, deberá anular el shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) para devolver SÍ cuando la aplicación debe rotar:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight; }

Esto le indicará al UIViewController que gire automáticamente si el dispositivo está en una de sus orientaciones compatibles. Si también deseaba apoyar la orientación invertida (retrato con el botón de inicio en la parte superior), agréguelo a su lista y solo responda SÍ a este método.

Haganos saber como funciona.


Swift 3 basado en el código de @Marjin.

var portraitOrientation = UIDevice.current.orientation == .portrait if UIDevice.current.orientation == .unknown || UIDevice.current.orientation == .faceUp { portraitOrientation = UIApplication.shared.statusBarOrientation == .portrait } if(portraitOrientation) { // Portrait } else { }