ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Mobile Application Development 2
    COMP4126
    Progress0 / 38 topics
    Topics
    1. Creating an iOS App: Understanding Xcode2. Using the Xcode interface builder and objects library3. Understanding view hierarchy and creating a custom app icon4. Outlets, Actions, and Views: Understanding outlets and actions5. Using text fields, buttons, labels, web views, and page controllers6. Using views with subviews and creating views using code7. Using View Controllers: Working with the single view template8. Exploring the app delegate and adding new view controllers9. Transitioning between multiple view controllers using animations10. Application Templates: Tabbar and master detail templates11. The iOS Keyboard: Customizing for different inputs12. Adjusting text field behaviors and dismissing the keyboard13. Detecting keyboard activities with notification center14. Using scroll view and responding to keyboard activities programmatically15. Working with Different iOS Devices (iPhone & iPad): Detecting device hardware16. Dynamically adjusting graphical layouts and creating universal apps17. Using Table Views: Understanding UITableView and UITableViewCell18. Working with UITableView data source and delegate19. Master detail template, drill-down menus, and navigation20. Using property lists for data persistence and creating multi-section tables21. Supporting Screen Rotations: Portrait and landscape modes22. Handling device rotation and forcing specific orientation23. Dynamically adjusting layouts based on rotation24. Working with Databases: Importing sqlite3 and creating a database25. Writing tables, inserting records, and bundling a database with your app26. Checking for database existence and reading/displaying data27. Using Animations & Video: NSTimer class and object transformations28. Rotation, scaling, translation, animating image arrays, and playing video29. Accessing Integrated iOS Apps: Email, Safari, and SMS30. Working with camera and photo library31. Using Web Services: Consuming and parsing XML and JSON32. Integrating Twitter and Facebook with iOS apps33. Working with iOS Maps and Location Services: MapKit and MKMapView34. Getting and displaying user location and directional information35. Displaying map annotations, disclosure buttons, and reverse geocoding36. Working with iCloud37. Working with the Accelerometer: Gyroscope and accelerometer38. Outputting sensor data and using the Shake API
    COMP4126›Supporting Screen Rotations: Portrait and landscape modes
    Mobile Application Development 2Topic 21 of 38

    Supporting Screen Rotations: Portrait and landscape modes

    3 minread
    575words
    Beginnerlevel

    📱 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

    • 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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time3 min
      Word count575
      Code examples0
      DifficultyBeginner