Limitations of iPad development
- When using Safari on the iPad to browse ordinary web pages, the web pages are too large and need to be manually zoomed in, zoomed out or swiped, although this kind of swipe The behavior was talked about in all kinds of publicity at the beginning of the iPad’s launch, but over time we will still find it inconvenient to do so, and the user experience is not very good.
- Flash is not supported. In the iPad Safari without jailbreak, the Flash of the website cannot be displayed, but it can be solved by third-party software or plug-ins or browsers. However, even if Flash cannot be displayed, you are the same The same effect can be achieved with HTML5 and CSS3.
- There is no mouse cursor, which means that mouse properties, such as mouse hover properties, are impossible. You may be able to find some workarounds for this, but it will be difficult to get to your users how to work.
- The scroll bar does not work as expected. The scroll bar cannot display content that contains too many partitions. The frame also has issues with height and width. In addition, a two-finger gesture is required during scrolling. (We will discuss fully below)
- Does not support CSS fixed layout HTML element position:fixed CSS property cannot be displayed correctly, often makes the page stay on the first screen, unable to page down and zoom in Zoom out.
iPad user detection: User Agent (User Agent)
With the popularization of Internet access on mobile devices, many websites will perform client browser type detection, mainly It is identified by the User Agent. If it is detected that it is a mobile phone browsing, it may be redirected to allow the user to browse the mobile device-specific version. In the past, the mobile devices we referred to were mainly mobile phones and other terminals. Now, the iPad has also joined the ranks of mobile terminal devices, but it has a 9.7″ large screen. The iPad’s Safari browser brings a browsing experience close to that of a PC computer. Therefore, the website page corresponding to the iPad must be different from other mobile devices, and the difference between the iPad access mainly depends on the User Agent of the browser.
The iPad Safari browser User described in iPhone OS 3.2 SDK beta 3 Agent code:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version /4.0.4 Mobile/7B334b Safari/531.21.10
The User Agent code of iPad Safari contains the words: “Mobile”, “iPad”, but does not contain the word: “iPhone”. This must be noted, If the previous version of the website did not distinguish between mobile device access, now it needs to be modified to prevent the wrong version from being returned to the corresponding device.
Imitate the iPad browser access method >
If you can’t test the webpage through the iPad or iPhone simulator, you can still test it in the following ways:
- Browse through the Mac OS X or Windows version of Safari The device acts as an emulator Safari menu -> Preferences -> Advanced -> Select Show “Development Menu” in the menu bar, this is the menu item “Development” will appear in the menu bar. Menu “Development” -> User Agent -> Other , Paste the above User Agent code in the pop-up dialog box, click OK, you can use Safari to verify whether the page is suitable for iPad display.
- Use Google Chrome as an emulator and enter the command line:
chrome.exe --user-agent="Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B500 Safari/531.21.10"
- Javascript detects the User Agent of the iPad, and then redirects to the URL of the corresponding version.
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {if (document.cookie.indexOf ("iphone_redirect=false") == -1) {window.location = "http://ipad.www.opensoce.com"; }}
- PHP script to detect User Agent
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) {header('Location: http://ipad.www.opensoce.com');exit();}
- Apache detects redirection
RewriteCond %{HTTP_USER_AGENT} ^iPad RewriteRule ^index\..*$ ipad.html [L] RewriteCond %{HTTP_USER_AGENT} ^iPhone RewriteRule ^index\..*$ iphone.html [L]
- Nginx detection Test direction
if ($http_user_agent ~*iPad) {proxy_pass http://ipad.www.opensoce.com;}if ($http_user_agent ~*iPhone) {proxy_pass http:// iphone.www.opensoce.com;}
Using W3C standard website technology
iPad and iPhone’s Safari browser does not support plug-ins and Flash.
The menu, navigation, etc. using plug-in technology (controls) will not be displayed in the browser of the iPad or iPhone.
The audio and video implanted by the plug-in will not be played. You can publish the audio and video content in the
In the past, you may need plug-ins to display animation content, and you can directly use the features of Javascript+CSS3 in the iPad and iPhone browsers. Make an animation. CSS3 began to develop in the direction of modularity, such as box models, list modules, backgrounds and borders, and so on. With CSS3, you can directly make rounded corner tables, which could only be achieved with pictures or VML technology before.
As for HTML5 and CSS3, the relatively early and successful application in China is NetEase’s three major mailboxes ((mail.163.com; mail.126.com; www.yeah.net), you are on the iPad When you enter the above address on the above address, you will be redirected to the iPad-compatible version, and the user feels very good. HTML5 has many advantages in standardization and speed. According to the data provided by NetEase, the speed of receiving letters and writing letters in this version is improved. 50%. In addition, another advantage is that the reduction in code size greatly improves the processing and operating efficiency of the mailbox server, and provides a more powerful platform for future function expansion.
The future and goals of HTML5/CSS3 It is to improve everyone’s web experience. An introduction to HTML5/CSS3:
* Use CSS3 gradients, font shadows, round boxes to borders-these are very simple and simple to the menu bar This is especially useful for website designers. * If you want to display videos, use HTML5 video player instead of Flash (obviously it won’t work). * Use HTML5 to create offline programs and store data offline. * Various practical tutorials are everywhere Yes, I used them when I was developing my iPad network program. Google and them got creative.
Using ordinary computer Safari to test the plug-in support situation, in Preferences->Security->, cancel the checkbox to enable the plug-in,
Set the viewpoint
Viewpoint can be understood as: window, viewable area, relative to the iPad hardware limited window The iPad window size cannot be changed, but the viewpoint window size can be adjusted.
If the window label setting is specified in the iPhone development, the necessary correction must be made in the iPad development. For example:
p>
In the iPhone, we will use the following code to specify the screen width
In iPad, device-width must be used instead of specific width pixels.
We While setting the width, you can set the zoomable scale range
Touch interaction
The external hardware keyboard is only an option for the iPad, and the touch screen keyboard is the main interactive tool for the iPad. When the user clicks the text box, the soft keyboard will automatically pop up, for example, when the user clicks or
iPhone and iPad users mainly interact with web pages through their fingers. The defect of this interactive method is that it cannot handle events similar to mouse stay. Therefore, mouse events in web pages: mousemove, mouseover, mouseout or CSS code: hover cannot achieve the performance effect in the PC browser.
Single-finger touch events (Touch Events): Single-finger DOM touch events that can be handled in iPhone and iPad browsers: touchstart, touchmove, touchend, touchcancel (when the system cancels the touch). Press and hold in the input box for a while and a cut/copy/paste window will pop up, which can be disabled on the webpage through the -webkit-user-select: none code.
Two-finger collaboration events (Gestures), that is It refers to the effect of zooming or rotating when two fingers touch the screen. For listening gestures, iPhone/iPad also has three events: gesturestart, gestureend, and gesturechange.
At the same time, the event parameter event has two attributes: scale and rotation. The median value of Scale is 1, greater than 1 means zoom in, and less than 1 means zoom out.
Simulation: hover pseudo-class
Because the iPhone does not have a mouse pointer, there is no hover event. Then the CSS :hover pseudo-class is useless. But iPhone has touch events, onTouchStart is similar to onMouseOver, and onTouchEnd is similar to onMouseOut. So we can use it to simulate hover. Use Javascript:
var myLinks = document.getElementsByTagName('a');for(var i = 0; iThen use CSS to increase the hover effect:
a:hover, a.hover {/* your hover effect*/ } pre>Designing a link like this makes it feel more like a button. And, this simulation can be used on any element.
Replace contenteditable with textareas
iPhone and iPad browsers do not support contenteditable elements.
Prevent automatic adjustment of font size when rotating the screen
-webkit-text-size-adjust is webkit’s private css:
html, body, form, fieldset, p, div, h1, h2, h3, h4, h5, h6 {-webkit-text-size-adjust:none;}Detect device rotation direction< /h3>
iPhone can browse the web in landscape mode. Sometimes you will want to know the handheld state of the user's device to enhance usability and functionality. The following piece of Javascript can determine which direction the device is rotating, and replace the css:
window.onload = function initialLoad() {updateOrientation();}function updateOrientation(){ var contentType = "show_"; switch(window.orientation){ case 0: contentType += "normal"; break; case -90: contentType += "right"; break; case 90: contentType += "left"; break ; case 180: contentType += "flipped"; break;} document.getElementById("page_wrapper").setAttribute("class", contentType);}CSS recognized by iPhone/iPad
If you don't want device detection, you can use CSS media queries to define styles specifically for iPhone/iPod.
@media screen and (max-device-width: 480px) {}CSS3 media query
For CSS3 For media queries, iPhone and iPad are different. Through this technology, different styles can be applied to different holding directions of the device, enhancing functions and experience.
iPhone is detected by the maximum width of the screen. It's like this:
The iPad is a bit different. It directly uses the orientation attribute in the media query. It's like this:
After that, just define different styles separately.
Shrink the image
The width of the large images of the website usually exceeds 480 pixels. If the zoom is restricted by the previous code, these images will obviously exceed the screen on the iPhone version. Fortunately, the function of the iPhone is enough, we can use CSS to make the iPhone automatically zoom out the big picture.
@media screen and (max-device-width: 480px){ img{max-width:100%;height:auto;}}Note that if the original picture is very large, or there are many pictures on a page, it is better to zoom to 480 pixels wide on the server side. The iPhone only needs to be zoomed to 320 pixels during normal browsing. This will not consume too much traffic and performance.
The toolbar is hidden by default
The iPhone browser toolbar will be at the top of the page and will be hidden after scrolling the web page. This is a waste of space after loading the webpage, especially when the screen is landscaped. We can make it scroll up automatically.
iPad icon
After the iPad is developed, the icons will be reflected in the following places:
- iPad desktop, png format icon not larger than 72×72; iPhone desktop, png format icon not larger than 57×57, add it in the resources section of Xcode, and set Icon file in xxxInfo.plist The attribute is the name of the added image resource. The icon file does not need to be rounded and reflective, the iPad/iPhone will do it by itself.
- The thumbnail shown in the software introduction in the App Store, the jpg image of iTunesArtwork placed in the root directory of the packaged zip file, the size is required to be less than 512×512
- If your users add your website to the home screen, the iPhone will use the thumbnail of the website as the icon. However, you can provide an icon of your own design, which is of course better. The picture is 57×57 size, png format. You don't need to make round corners and reflections yourself, the system will automatically complete these tasks. Then add the following to the head:
< /ol>
Use iScroll to control your touch scrolling
This is a simple and most useful source code that can help you control your web applications. Created by Matteo Spinelli, iScorll is a development project because the web browser engine Webkit toolkit (used on iPhone, iPod, iPad, Android and Palm) does not provide a local way to scroll a fixed height/width element inside the article.
This unfortunate situation prevents any web application from having a header and/or footer position:absolute CSS property and scrolling the content in the center area.
The iScroll code is very easy to use. If you like iScroll, you need these similar jQuery plugins: jQuery Swipe and JQTouch.
iPad native apps
* Native apps run faster: use more iPad resources and performance. * No need to search on the Internet: one-stop shopping on the Apple Store. * Users feel more comfortable: They know that the program is specially made for their device and is not suitable for HTML5/CSS3. * Easier to open and close: There is no interruption and no data loss when the program is opened and closed. * Harder to develop: requires knowledge of Objective-C and Apple SDK. * Closed platform: It is difficult to modify for other devices such as the Android platform.iPad web application
* Emerging coding standards: HTML5, CSS3, and JavaScript are bringing amazing client functions to the web; Especially the local/offline storage function. * The site can be customized for any browser: switch style sheets or redirect web pages according to the device or browser operated by your users. It can make your application universal. * Simple development: Use HTML, CSS and JavaScript to create iPad web applications instead of learning new languages. You should already have these skills. * Steve Jobs can’t censor your web programs: the web is an open platform – meaning that you are all under your control and you don’t need to wait for the approval of the Apple Store. * Niche market, not enough support: Web applications need a lot of power, not only to attract users but also developers to participate.