Tags down


UICollectionView cell spacing for both portrait and landscape

By : Babysungit Dereje
Date : October 18 2020, 06:10 PM
I wish did fix the issue. My goal is to make equal spacing between the cells for the portrait and landscape orientation. I am able to do it for the portrait orientation but not for the landscape orientation. I wanted to close the gap in the landscape orientation by stretching the image width and height. , Try this:
code :
override func viewDidLoad() {
    collectionView.backgroundColor = .white
    collectionView.alwaysBounceVertical = true
    collectionView.contentInsetAdjustmentBehavior = .always
    collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 5

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
    cell.backgroundColor = .blue
    return cell

var spacing: CGFloat = 8

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return spacing

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return spacing

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    let safeFrame = view.safeAreaLayoutGuide.layoutFrame
    let size = CGSize(width: safeFrame.width, height: safeFrame.height)
    return setCollectionViewItemSize(size: size)


override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {

func setCollectionViewItemSize(size: CGSize) -> CGSize {
    if UIApplication.shared.statusBarOrientation.isPortrait {
        let width = (size.width - 1 * spacing) / 2
        return CGSize(width: width, height: width)
    } else {
        let width = (size.width - 2 * spacing) / 3
        return CGSize(width: width, height: width)

Share : facebook icon twitter icon

how to give smooth transaction in iPad when we change landscape to portrait or portrait to landscape

By : Javito Bertolino
Date : March 29 2020, 07:55 AM
To fix this issue I designed iPad based website with pure HTML and CSS, everything work pretty good, but only one thing that I have noticed and it is about the smoothness when we change device view(From landscape to Portrait or reverse) its change with little jerk. , Finally this is fixed with simple meta tag. :-)

cancellation of the content of the EditText when changing from PORTRAIT to Landscape and landscape to portrait

By : illyasviel
Date : March 29 2020, 07:55 AM
Does that help Everytime orientation change, android create new view and destroy the old one. You can save your data when orientation change and re-initialize when the new view is created
Use onConfigurationChanged method of activity to detect Orientation Change
code :
public void onConfigurationChanged(Configuration newConfig) {

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
<activity android:name=".MyActivity"

uicollectionview cell frame in portrait and landscape

By : Dudu Dada
Date : March 29 2020, 07:55 AM
wish help you to fix your issue i faced similiar problem so basically you should implement UICollectionViewDelegateFlowLayout in your view controller otherwise design a custom collectionviewcell and register in your view controller , it will definitely work . Try it .
in my case i added xib by subclassing UICollectionViewCell and designed it accordingly and it works so you may try .

UICollectionView from portrait to landscape

By : Eduardo Mendes
Date : March 29 2020, 07:55 AM
like below fixes the issue Apple deprecated the method of willRotateMethod in iOS 8 SDK. so what you write code in didRotateMethod method that code you will write in viewDidLayoutSubviews so your problem will be solved.

How to fix item width in UIcollectionView when moving from portrait to landscape?

By : John
Date : March 29 2020, 07:55 AM
This might help you You can override viewWillTransition method and reload so that collectionView recalculate the size.
code :
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

Related Posts Related Posts :
  • How to create UIButton Pulse animation using Swift?
  • using swift can we airplay photos on Apple TV programmatically?
  • Where to find the shared secret for iOS App Store receipt validation?
  • AVRoutePickerView Won't Change Color when Airplay is Active
  • What sections of Apple Health app are available via the x-apple-health:// URL scheme?
  • Flutter error on pod install: CocoaPods could not find compatible versions for pod "Firebase/CoreOnly"
  • RegEx for matching specific URLs with lowercase and dashes
  • How to build and use C library in iOS project?
  • How to capture cell data from UITableView with multiple cell prototypes?
  • Swift run multiple block of codes asynchronously in background thread in order
  • how do I trigger the click event on AVRoutePickerView using swift
  • Animate UIImageView start from rounded topRight corner and end with Rectangle
  • Xamarin.iOS binding for a swift library
  • Converting JSON String to Dictionary<String, Any> serializes Boolean as Int
  • How to keep tableFooterView always on bottom of UITableView
  • Why not getting response from one URL?
  • Why might my iOS app be stuck on splash screen for Apple reviewers but not for me?
  • Installing .ipa over the air does not open
  • How to Add Business Logic in CollectionView?
  • is there a shortcut to know, when I'm running my app, which view controller am I in?
  • error: Unable to load contents of file list: '/Target Support Files/Pods-xx/Pods-xx-frameworks-Debug-input-files.xcfilel
  • Encode and Decode a Class in ios
  • How to get device token using firebase?
  • Removing duplicate objects from fetch based on object parameter UPDATED Swift
  • Class variable assignment is not working inside a Alamofire request block
  • Is it possible to do Augmented Faces on iOS with ARCore?
  • How to differentiate between event saved through my app and event saved by using calendar app using EventKit?
  • Pushing Firebase events To a Table View
  • What happens to local files on iOS when the app is updated?
  • How to make a variable accessible from a different swift file?
  • I want to generate QR Code encrypted in such a way that it is only read by own QRScanner app
  • Update Phone Number in Firebase Authentication - Swift
  • Convert bits per second (bps) to a human readable size format
  • How to not invalidate observer when binding is disposed in RxSwift?
  • What happen if I return false in didFinishLaunchingWithOptions?
  • How to detect hand palm and its orientation (like facing outwards)?
  • New OutputDeviceUID is nil msg when instantiating MPVolumeView
  • How to add sound feedback like pickerview in collectionview?
  • Cannot assign value of type '[String]' to type 'String?'
  • How do I make an iOS app support iPhone 6, without supporting iPhone 5S?
  • iOS app -- no cellular access to our domain on some devices
  • How to show image from url in ios swift
  • Importing image from photo library into an app in xcode
  • Delegate won't work using three view controllers
  • Why can such code be compiled? Call popToRootViewControllerAnimated in iOS UIViewController?
  • Open native UIViewController in Flutter
  • How to place 3D object (.scn file) on detected vertical plane which should be parallel to plane in ARKIt?
  • Delegate data from one UIViewController to another one
  • WARNING: The advertisement key 'Service Data' is not allowed
  • How do I check if a particular app is installed on the user's device on iOS?
  • How to check if user has paid for an Auto Renewal Subscription In App Purchase in Swift
  • Dynamic-height UICollectionView inside a dynamic-height UITableViewCell
  • This iPhone 7 (Model 1660, 1778, 1779, 1780) is running iOS 12.3.1 (16F203), which may not be supported by this version
  • How to fix issue: no rule to process file /FBSDKCoreKit.modulemap' of type 'sourcecode.module-map' for architecture x86_
  • Apple iOS Inapp purchase Server to Server Notifications' 'Cancel' notification cases?
  • Cannot assign to property 'observationTime' is a get-only property
  • How do I use Codable to decode json response which has changing keys?
  • Saving an array in Swift
  • Swift pushViewController Works on iPad but not iPhone
  • Parsing JSON response into a struct
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk