"Exploring the relationship between UIWebView and CSS's fixed positioning

My UIWebView is set up with a fixed position header.

Everything works seamlessly when the initial view of the ViewController containing the UIWebView is displayed.

However, if I present that same ViewController using a Modal segue, an issue arises.

When I first scroll on the page, the divs shift and scroll along with the content. But as soon as I stop scrolling for the first time, the div snaps back to its fixed position, and the problem never reoccurs.

Any suggestions? While I've looked into iScroll, it doesn't quite fit the functionality I'm seeking for the page. I believe there must be a simpler solution, especially since the problem only occurs during the initial load of the UIWebView...

Answer №1

To address the issue, I implemented a CSS hack by setting the header to absolute positioning in the top left corner. Additionally, I applied an overflow-y: scroll; property to the main <div> and specified body { height: 100%; }.

This workaround effectively created a makeshift version of iScroll!

UPDATE

Furthermore, for a smoother user experience, you can add:

-webkit-overflow-scrolling: touch;

To the main <div> style for a more natural scrolling effect.

Answer №2

Regrettably, the reliability of position: fixed on iOS is still questionable. This means some compromises will need to be made.

iScroll might be a potential solution, but it is essentially a workaround. It may not always provide the desired "fixed" appearance due to slow scrolling on certain devices.

Without much information about the content of the header, here are a few alternative options to consider:

a. Place any elements requiring fixed positioning at the top of the screen in a UIView within your ViewController, placing the UIWebView below.

b. Adjust your storyboard layout to remove the necessity for a modal segue.

c. Consider avoiding the use of storyboards altogether to avoid issues with segues.

d. Revise your HTML structure to eliminate the need for a fixed header.

Provide more details about the contents of the fixed header, and we can explore additional ideas together.

Answer №3

position: sticky is not fully supported on iOS devices at the moment.

If you want a reliable solution, consider using iScroll.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to create a footer design featuring buttons aligned to the left and right sides

I am trying to create a layout similar to the bottom of Google's homepage using this code. However, no matter what I try, the "lists" are still appearing vertically instead of horizontally. My goal is to have three columns of links positioned side by ...

Transitioning Dropdowns in Angular UI Bootstrap

Hello everyone, I am completely new to both Stack Overflow and AngularJS. I'm attempting to incorporate a fade-in animation into my dropdown (using UI Bootstrap's dropdown directive) without success. This issue is quite similar to the following ...

Converting a 'div' element into a dropdown menu with CSS and Jquery

I am facing a challenge where I have a collection of buttons enclosed in a div that I want to resemble a dropdown: <div id = "group"> <label> Group: </ label> <div value =" 1hour "> 1h < / div> <div value =" 2hou ...

Are there any Android counterparts to plist files similar to what we see in iOS?

Is there a similar method in Android to quickly read and write data from a file like iOS does with plist files using NSDictionary? I have experience creating an app on iOS that utilized a plist file with hundreds of entries, which is essentially just XML ...

Child element casting shadow over parent element

I am currently using box shadow for both the parent (.map) and child (.toggle-button): .map { position: fixed; top: 20px; right: 0; width: 280px; height: 280px; z-index: 9999; box-shadow: 0px 1px 6px 0px rgba(0,0,0,0.3); } .map ...

Material-UI's simplification of 10px comprehension

I'm a bit confused about why we have to do this for the 10px simplification: html { font-size: 62.5%; /* 62.5% of 16px = 10px */ } Shouldn't the following code handle everything? const theme = createMuiTheme({ typography: { // Set the ...

designing a personalized two-row navbar layout in Bootstrap 4

I have been attempting to design a unique custom navigation bar that I haven't come across anywhere else online. Despite my diligent search for examples or solutions, I have not been able to find what I am looking for. Therefore, I am reaching out her ...

Customizing Bootstrap CSS

In my recent code, I included a bootstrap css reference in this manner: <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5T ...

Swift code encounters date formatting mishap

I am trying to format a date in the medium format as follows: Jul 17, 2016 4:30:00 PM, however, I am receiving 07/17/2016 4:30:00 p.m. Any assistance would be greatly appreciated. Thank you in advance. this is the code I am using: let dateFormatter = NS ...

Optimizing background images for various mobile devices using PhoneGap

Currently in the process of creating a cross-platform app for iOS and Android using Phonegap. Facing an issue with implementing a background-image as it gets cropped or distorted on various mobile devices due to size differences. Managed to address this ...

Move the container all the way to the left

On my page, I have a grey section with the heading 'Start Analysis' that needs to be shifted to the left along with all its contents. How can this be achieved? The HTML code for the section is as follows: <!DOCTYPE html> <html lang="en ...

Arranging objects in an NSMutableArray in a specific order

Seeking assistance from knowledgeable individuals. I am currently working on populating a NSMutableArray with multiple objects and I require assistance in sorting the order based on the first element, which will invariably be a number. Any advice on how ...

Customizing ExtJS 4's CSS reset specifically for tailored HTML inside components

I am currently in the process of upgrading an existing application from Ext 3.x to 4. I have successfully enabled Ext's scoped reset CSS option to prevent Ext from applying its CSS reset to my entire application. However, I am now facing a new issue. ...

What are the steps to enable a web app on a user's home screen?

Hey there! I'm looking to add a small popup with a button at the end of my website to prompt users to add it to their phone's home screen. I followed a tutorial that helped me achieve this on Android, but unfortunately, it only works with https a ...

Design elements for React and Angular JS

Is there a way to design UI components in a style that is compatible with both Angular JS and React? These two technologies will be utilized simultaneously within the same application. ...

Animating CSS when closing a modal box

I followed the instructions from a tutorial on W3Schools here to create this code. The "open model" button triggers the modal to open with a smooth CSS animation, which looks great. However, when I click the close button, the modal abruptly closes without ...

What is the best way to add a class to the initial HTML element in my specific scenario?

Currently utilizing the angular framework in my application. Desire to assign a specific class to only the initial element within my ng-repeat iteration. <div class='initialOnly' ng-repeat = 'task in tasks'>{{task.chore}}</di ...

Enhance your images with Jquery thumbnail zoom feature

I am in the process of creating color swatches for clothing items, using them as a reference point. http://jquery.malsup.com/cycle/pager7.html Take a look at the thumbnails on the webpage mentioned above. My goal is to display these thumbnails without re ...

Uploading images using the Drag and Drop feature in HTML

Hello, I'm having an issue with the drag and drop functionality. I want to expand the size of the input to cover the entire parent div, but for some reason, the input is appearing below the drag and drop div. Can anyone assist me with this? https://i. ...

Issue with Inserting a Video in Swift

Having trouble playing a video in the background. The code I'm using is: import UIKit class ViewController: VideoSplashViewController { override func viewDidLoad() { super.viewDidLoad() let path = NSBundle.mainBundle().pathFor ...