Capture iPad orientation change

Share this article

Code snippet to capture the change of orientation on your ipad device
, you can then add very specific styles for each portrait and landsacape designs. The code adds a class to the html tag to assist with CSS (just like libraries such as Modernizr) using CSS3 media queries.
jQuery(document).ready(function($) {
 //capture ipad device change
function doOnOrientationChange()
{
    switch(window.orientation)
    {
      case -90: 
      case 90:
        alert('landscape'); //debug
        ////add class to assist with libraries like Modernizr
        $('html').removeClass('portrait').addClass('landscape'); 
        break;
      default:
        alert('portrait'); //debug
        $('html').removeClass('landscape').addClass('portrait');
        break;
    }
}

//setup event listener
window.addEventListener('orientationchange', doOnOrientationChange);

//initial call
doOnOrientationChange(); 
});
Example of CSS use.
/* styles for tablet only */
@media (min-width: 768px) and (max-width: 1024px)  {

    .portrait {

        /* styles for ipad landscape orientation */

    }    

    .landscape {

        /* styles for ipad landscape orientation */

    }
}

Frequently Asked Questions about iPad Orientation Change

How can I lock the orientation on my iPad?

To lock the orientation on your iPad, you need to access the Control Center. You can do this by swiping down from the top-right corner of your screen. Once the Control Center is open, look for the icon that resembles a lock with an arrow circling it. This is the orientation lock button. Tap it to lock your iPad’s screen orientation. When the button is highlighted, the orientation is locked. To unlock it, simply tap the button again.

Why is my iPad not changing orientation?

If your iPad is not changing orientation, it could be due to a few reasons. The most common reason is that the orientation lock is enabled. You can check this by opening the Control Center and looking for the orientation lock button. If it’s highlighted, tap it to unlock the orientation. If the problem persists, try restarting your iPad as it could be a temporary software glitch.

Can I change the orientation settings on my iPad?

Yes, you can change the orientation settings on your iPad. You can choose to lock the orientation in either portrait or landscape mode. To do this, open the Control Center and tap the orientation lock button. Then, rotate your iPad to the desired orientation before tapping the button again. Your iPad will now be locked in your chosen orientation.

How do I change the orientation on my iPad without the lock button?

If your iPad’s lock button is not working, you can still change the orientation through the AssistiveTouch feature. Go to Settings > Accessibility > Touch > AssistiveTouch and turn it on. Then, tap the AssistiveTouch button on your screen, select Device, and then Rotate Screen. You can now choose the desired orientation.

Why does my iPad screen keep rotating?

If your iPad screen keeps rotating, it’s likely because the orientation lock is not enabled. To stop the screen from rotating, you can lock the orientation through the Control Center. Simply swipe down from the top-right corner of your screen, and tap the orientation lock button.

Can I set my iPad to automatically change orientation?

By default, your iPad is set to automatically change orientation when you rotate the device. If this is not happening, ensure that the orientation lock is not enabled. If the problem persists, try restarting your device or updating your iPad’s software.

How do I change the orientation on my iPad Pro?

Changing the orientation on an iPad Pro is the same as on other iPad models. You can rotate the device to change the orientation, or lock the orientation through the Control Center. If you want to lock the orientation, swipe down from the top-right corner of your screen to open the Control Center, and tap the orientation lock button.

Can I change the orientation on my iPad while using a specific app?

Yes, you can change the orientation on your iPad while using a specific app. However, some apps only support one orientation, either portrait or landscape. If you’re unable to change the orientation while using an app, it’s likely because the app doesn’t support the other orientation.

Why is my iPad stuck in landscape mode?

If your iPad is stuck in landscape mode, it could be because the orientation lock is enabled. Check this by opening the Control Center and looking for the orientation lock button. If it’s highlighted, tap it to unlock the orientation. If the problem persists, try restarting your iPad or updating your software.

How do I rotate the screen on my iPad Mini?

To rotate the screen on your iPad Mini, simply rotate the device to your desired orientation. If the screen doesn’t rotate, check if the orientation lock is enabled by opening the Control Center. If the orientation lock button is highlighted, tap it to unlock the orientation.

Sam DeeringSam Deering
View Author

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

jQuery
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week