for i want to build a movie controller,and it`s pushed by a navigationController,how can i set it ,also only this vc can be landscape,others should only be portraitUp,please help,thanks in advance.
Try..
- (void)viewDidAppear:(BOOL)animated
{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
}
- (void)viewDidDisappear:(BOOL)animated
{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
}
Related
I have tried many codes from this website and others too.... But nothing seems to be working for me. Here is my code...
- (IBAction)orientation:(id)sender {
self.currentDeviceOrientation = [[UIDevice currentDevice] orientation];
int cur = self.currentDeviceOrientation;
int port = UIInterfaceOrientationPortrait;
int landl = UIInterfaceOrientationLandscapeLeft;
int landr = UIInterfaceOrientationLandscapeRight;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
NSNumber *value= [NSNumber numberWithInt:UIDeviceOrientationLandscapeLeft];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"orientation"];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
}
}
on the click of a button, I want the screen to change from its current orientation i.e, if the screen is in portrait mode, it should change in to landscape and vice-verse.
Try this and change as what you need.
- (IBAction)orientation:(id)sender {
if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeLeft){
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
NSLog(#"landscape left");
}
if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationLandscapeRight){
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
NSLog(#"landscape right");
}
if ([[UIDevice currentDevice]orientation] == UIInterfaceOrientationPortrait){
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
NSLog(#"portrait");
}
}
You need to set orientation as per your needs.
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
This line of code always fail on iOS 9.2 Simulator, but it is ok on iOS 8.4 and iOS 10.1 Simulators
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:#"orientation"];
It trows this error
XPC connection interrupted
Terminating since there is no system app.
I created a new MasterDetail Application in XCode and this is viewDidLoad method in the DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:#"orientation"];
}];
}
here is what I'm trying to achieve, it would be to send an action on rotation of the device...
the point is i'm having a 360 player, I would like the video to start only once the device is on landscape. If it's in portrait i'd like to display a message a saying "rotate your device in landscape to start", and when the user rotate the device, the video play.
below is my code so far:
- (IBAction)test:(id)sender forEvent:(UIEvent *)event {
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"demo1" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:#"HTY360PlayerVC" bundle:nil url:url];
[videoController VRMode:true];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
{
NSLog(#"UIDeviceOrientationPortrait");
}
}
The problem of this code is than it trigger only on TouchUp Inside in the Sent Event . . . anyway to have the action starting on rotation ?
Thanks for all your help !
EDIT---
TRYIED THE FOLLOWING ASWELL:
- (IBAction)test:(id)sender forEvent:(UIEvent *)event {
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"demo1" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
Video360ViewController *videoController = [[Video360ViewController alloc] initWithNibName:#"HTY360PlayerVC" bundle:nil url:url];
[videoController VRMode:true];
if (![[self presentedViewController] isBeingDismissed]) {
[self presentViewController:videoController animated:YES completion:nil];
}
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
{
NSLog(#"UIDeviceOrientationPortrait");
}
}
Have you tried
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
Try put your code inside:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
}
and write this methods in your UIViewController. This method is called when the device (interface really) is rotated; if you want do something before the rotation of interface, use willRotateFromInterfaceOrientation
What I am trying to do is make it so that when an iBeacon has been found (when the user is on the home screen), it sends them to another part of the app. Essentially it pushes another view of the app from the storyboard. For example, iBeacon1 pushes View1, iBeacon2 pushes View2, etc, and that's it. Like I said I know that it possible, but because iBeacons are quite new, there isn't much help available.
I would really appreciate it if you could take some time out of your day to help me with this issue that I cannot find the answer to.
Thank you for your time,
Josh
If you are using Storyboards, you could do something like this in your AppDelegate:
var launchedViewControllers = [Int]()
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if let navController = self.window?.rootViewController?.navigationController {
for beacon in beacons {
if (beacon.minor == 1) {
if !launchedViewControllers.contains(beacon.minor.integerValue) {
launchedViewControllers.append(beacon.minor.integerValue)
let viewController1 = mainStoryboard.instantiateViewControllerWithIdentifier("viewController1")
navController.pushViewController(viewController1, animated: true)
}
}
if (beacon.minor == 2) {
if !launchedViewControllers.contains(beacon.minor.integerValue) {
launchedViewControllers.append(beacon.minor.integerValue)
let viewController2 = mainStoryboard.instantiateViewControllerWithIdentifier("viewController1")
navController.pushViewController(viewController2, animated: true)
}
}
}
}
}
You could also rewrite this to use segues instead of programmatically pushing ViewControllers using a NavigationController but both will work.
pragma mark -
pragma mark -Important Methods
-(void)showSecondController{
if ([_beacon.major isEqual: #3404] && [_beacon.minor isEqual: #10692]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SDOVideoDetailController"];
} else if ([_beacon.major isEqual: #20165] && [_beacon.minor isEqual: #53849]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"LRCVideoDetailController"];
} else if ([_beacon.major isEqual: #53088] && [_beacon.minor isEqual: #30487]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"CECSVideoDetailController"];
} else if ([_beacon.major isEqual: #55304] && [_beacon.minor isEqual: #59835]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"IVideoDetailController"];
} else if ([_beacon.major isEqual: #16004] && [_beacon.minor isEqual: #46054]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"CILVideoDetailController"];
} else if ([_beacon.major isEqual: #20214] && [_beacon.minor isEqual: #11696]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"ITVideoDetailController"];
} else if ([_beacon.major isEqual: #21559] && [_beacon.minor isEqual: #17557]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PARKVideoDetailController"];
} else if ([_beacon.major isEqual: #59452] && [_beacon.minor isEqual: #21013]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SCVideoDetailController"];
} else if ([_beacon.major isEqual: #42093] && [_beacon.minor isEqual: #49773]) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:#"orientation"];
self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"BAVideoDetailController"];
}
My app will be launched in Landscape,only one view can change to Portrait, in which there is a button,I click this button to change the orientation to Portrait.
It performed as expected on iPad(iOS 8.4,Deployment target: 7.0),and I made an iPhone version,in which I just made some adjust on UI,and it runs on iPhone 6 Plus simulator(Base SDK: 9.1,Deployment target: 7.0),but the button for chagning orientation doesn't work.
And I want to know how to implement this in iOS 9;
The Below is my code:
- (void)changeOrientation
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation==UIInterfaceOrientationLandscapeLeft||orientation==UIInterfaceOrientationLandscapeRight){
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationLandscapeLeft) {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
}
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"ScreenToPortrait" object:nil];
}else{
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationPortrait) {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
}
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"ScreenToLandscapeLeft" object:nil];
}
[UIViewController attemptRotationToDeviceOrientation];
}
This works on iOS9
NSNumber *orientationValue = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue: orientationValue forKey:#"orientation"];
Go to General tab from app target, and enable all orientations.
For all view which support only landscape orientation implement supportedInterfaceOrientations() and return landscape orientation value.
seen or set tick on General setting.