ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP4126Screen Rotations Portr…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP4126

    Mobile Application Development 2

    Progress0 / 38 done
    Topics38
    1Understanding Xcode2Using the Xcode interface builder and objects library3Understanding view hierarchy and creating a custom app icon
    4Understanding outlets and actions5Using text fields, buttons, labels, web views, and page controllers6Using views with subviews and creating views using code
    7Working with the single view template8Exploring the app delegate and adding new view controllers9Transitioning between multiple view controllers using animations
    10Tabbar and master detail templates
    11Customizing for different inputs12Adjusting text field behaviors and dismissing the keyboard13Detecting keyboard activities with notification center14Using scroll view and responding to keyboard activities programmatically
    15Detecting device hardware16Dynamically adjusting graphical layouts and creating universal apps
    17Understanding UITableView and UITableViewCell18Working with UITableView data source and delegate19Master detail template, drill-down menus, and navigation20Using property lists for data persistence and creating multi-section tables
    21Portrait and landscape modes22Handling device rotation and forcing specific orientation23Dynamically adjusting layouts based on rotation
    24Importing sqlite3 and creating a database25Writing tables, inserting records, and bundling a database with your app26Checking for database existence and reading/displaying data
    27NSTimer class and object transformations28Rotation, scaling, translation, animating image arrays, and playing video
    29Email, Safari, and SMS30Working with camera and photo library
    31Consuming and parsing XML and JSON32Integrating Twitter and Facebook with iOS apps
    33MapKit and MKMapView34Getting and displaying user location and directional information35Displaying map annotations, disclosure buttons, and reverse geocoding36Working with iCloud
    37Gyroscope and accelerometer38Outputting sensor data and using the Shake API
    3 min read
    Topic 21 of 38
    Topic Study Note Illustration
    21

    Supporting Screen Rotations: Portrait and landscape modes

    Screen rotation support in iOS means designing an app so that its UI automatically adjusts when the device changes orientation :

    πŸ“± Supporting Screen Rotations: Portrait and Landscape Modes (iOS – Xcode)


    βœ… 1. Definition

    Screen rotation support in iOS means designing an app so that its UI automatically adjusts when the device changes orientation:

    • πŸ“± Portrait mode β†’ vertical layout (height > width)
    • πŸ“± Landscape mode β†’ horizontal layout (width > height)

    πŸ‘‰ A well-designed app looks good and works properly in both modes.


    🧠 2. Key Concepts

    πŸ”Ή Orientation

    The direction in which the device is held:

    • Portrait
    • Landscape Left
    • Landscape Right

    πŸ”Ή Auto Layout

    • System that automatically adjusts UI constraints
    • Essential for rotation support

    πŸ”Ή Size Classes

    • Help adapt UI for different screen sizes and orientations

    • Example:

      • Compact width (portrait iPhone)
      • Regular width (landscape/iPad)

    πŸ”Ή Trait Collection

    • Provides information about current device environment
    • Used to adjust UI dynamically

    πŸ”„ 3. How Screen Rotation Works

    Device Rotates
          ↓
    iOS detects orientation change
          ↓
    Layout updates using Auto Layout / Size Classes
          ↓
    UI adapts to new screen size
    

    βš™οΈ 4. Enabling Rotation in iOS


    πŸ”Ή Step 1: Allow Orientations in Project

    In Xcode:

    • Go to Target β†’ General β†’ Deployment Info

    • Enable:

      • Portrait
      • Landscape Left
      • Landscape Right

    πŸ”Ή Step 2: Override Supported Orientations (Optional)

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return [.portrait, .landscapeLeft, .landscapeRight]
    }
    

    πŸ“ 5. Handling Layout Changes Programmatically


    πŸ”Ή Detect Orientation Change

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        
        if size.width > size.height {
            print("Landscape Mode")
        } else {
            print("Portrait Mode")
        }
    }
    

    πŸ”Ή Using Device Orientation

    if UIDevice.current.orientation.isLandscape {
        print("Landscape")
    } else {
        print("Portrait")
    }
    

    🧩 6. Adjusting UI for Rotation


    πŸ”Ή 1. Auto Layout (Best Method)

    • Constraints automatically adjust UI
    • No manual coding needed

    πŸ”Ή 2. Stack Views

    Stack (abstract data type)
    Visual ReferenceStack (Abstract Data Type)
    Wikipedia
    • Automatically rearrange elements:

      • Vertical β†’ Portrait
      • Horizontal β†’ Landscape

    πŸ”Ή 3. Manual Layout Adjustment

    if UIDevice.current.orientation.isLandscape {
        label.font = UIFont.systemFont(ofSize: 24)
    } else {
        label.font = UIFont.systemFont(ofSize: 18)
    }
    

    πŸ“Š 7. Diagram Description (for Exams)

    Draw:

    Portrait Mode          Landscape Mode
       πŸ“±                     πŸ“±
      | App |               | App        |
      | UI  |               | UI Layout  |
      |_____|               |___________|
    

    πŸ’‘ 8. Example App

    🎯 Photo Gallery App

    • Portrait:

      • 1 column grid
    • Landscape:

      • 3 column grid

    πŸ‘‰ Layout changes automatically based on orientation


    πŸ“Œ 9. Important Rules / Tips

    • Always use Auto Layout (mandatory for rotation support)
    • Use Stack Views for flexible UI
    • Test both orientations in simulator
    • Avoid fixed frame layouts
    • Use Safe Area for proper positioning

    ⚠️ 10. Common Mistakes

    • ❌ Fixed screen coordinates (breaks rotation)
    • ❌ Not enabling landscape mode
    • ❌ Ignoring Safe Area
    • ❌ Poor constraint setup
    • ❌ Not testing both orientations

    🧠 11. Best Practices

    • Design adaptive UI from the start
    • Use Size Classes + Auto Layout
    • Test on multiple devices
    • Keep UI simple and flexible
    • Use stack views instead of manual positioning

    πŸ“ 12. Likely Exam Questions

    1. What is screen rotation in iOS?
    2. Differentiate between portrait and landscape modes.
    3. How do you enable rotation in Xcode?
    4. What is Auto Layout and why is it important for rotation?
    5. How do you detect orientation changes in code?
    6. What are Size Classes?
    7. Why should fixed layouts be avoided?
    8. Explain view adjustment during rotation.

    πŸ“š 13. Quick Revision Summary

    • Screen rotation = switching between portrait & landscape

    • iOS automatically adjusts UI using:

      • Auto Layout
      • Size Classes
    • Key methods:

      • viewWillTransition
      • UIDevice orientation
    • Always design responsive UI

    • Test both orientations for best results


    ← Previous topic 20
    Using property lists for data persistence and creating multi-section tables
    Next topic 22 β†’
    Handling device rotation and forcing specific orientation

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    3mremaining
    582words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Mobile Application Development 2