IOS solution for earlier version compatibility

Source: Internet
Author: User

The Objective-C2.0 provides the category mechanism to expand existing objective-C classes. We can use the category mechanism to solve the problem that some methods of the existing cocoa framework have too many versions.

For example, in uiwebview, the system displays the content to the Web View Based on the HTML attributes. At this time, when it encounters the retina display flag, uiwebview automatically calls the setcontentscalefactor method of uiview internally to set the resolution scaling factor. This method is available only after ios4.0 and later. If the ios3.2 system is used, the application will crash.

We can solve this problem by adding:

@ Interface uiwebview (notexpected)

-(Void) setcontentscalefactor :( cgfloat) factor;

@ End


@ Implementation uiwebview (notexpected)

-(Void) setcontentscalefactor :( cgfloat) factor
{
If (! [[Uiview class] respondstoselector: @ selector (animatewithduration: Animations :)])
Return;
Else
[Super setcontentscalefactor: factor];
}

@ End

Use the animatewithduration: Animations: Method in the uiview to check whether the system is ios4.0 or later. If it is not 4.0, it is returned directly. If it is version 4.0 or later, you can directly call the uiwebview parent class, that is, the setcontentscalefactor method of uiview.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.