(IOS) Project summary-Various problems and workarounds encountered in the project

Source: Internet
Author: User

Objective:

One to the company reported at that time, then embarked on an independent to complete a project, of which the bitterness of tears is also outsiders. This is a new kind of app, still independent development, but the mood and ideas are completely different. The following is a previous development often overlooked knowledge, is a kind of review it. The following:

1. Next usage with keyboard

This is more commonly used, as long as we think of login and registration interface, it should be natural to think of-the keyboard next usage (of course, not to exclude quite a lot of software does not implement this function).

The idea is that the user after entering the user name, click Next to jump to the next input box. In fact, do not think so complicated, in the login interface, we can use an if statement to make judgments, to achieve the keyboard response and logoff response.

The code is as follows:

-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField {

Uitextfield *passtextfiled = (Uitextfield *) [Self.view viewwithtag:201];

if (Textfield.tag = = 200) {

[Passtextfiled Becomefirstresponder];

}else{

[Passtextfiled Resignfirstresponder];

}

return YES;

}

This simply switches the input box between the response and the logout response.

But there is still a problem, if I implement the registration interface jump input box, and in the input box a lot of cases, obviously if I still judge, will appear verbose and redundant.

I had thought of using count to record the tag of each click Next, but it failed in practice, because when I did not pass next instead of touching the input box directly with my hand, I could not count.

Let's leave a blank here, and then look at the problem when the project is finished in the hand.

2, Uitextfield error correction and first letter case-sensitive problem

This problem is just a simple attribute problem, in the development of If you forget, suggest to go to see more, (such as: Command + Uitextfield)

Whether there is a fork in the input box, when displayed, used to delete the contents of the input box at once self.clearbuttonmode = uitextfieldviewmodewhileediting;

Whether error correction, I feel error correction is a very offensive thing, but Uitextfield default is yes, here I changed to no self.autocorrectiontype = Uitextautocorrectiontypeno;

Edit again to empty self.clearsonbeginediting = YES;

Sets the minimum font size for the auto-shrink display self.minimumfontsize = 15;

Setting the keyboard style, I feel that this setting has an impact on the user experience. For example, I want to call, type Uikeyboardtypenumberpad, not other

Self.keyboardtype = Uikeyboardtypenamephonepad;

3, the use of several stretching methods of pictures in iOS

Here are 3 ways Apple gives:

UIImage *image = [UIImage imagenamed:@ "picture"];

Before IOS5

Left cover width

Nsinteger leftcapwidth = image.size.width * 0.5f;

Nsinteger topcapheight = image.size.height * 0.8f;

image = [Image stretchableimagewithleftcapwidth:leftcapwidth Topcapheight:topcapheight];

After iOS5

Uiedgeinsets insets = Uiedgeinsetsmake (image.size.height * 0.8f,image.size.width * 0.5f, 40, 40);

image = [Image resizableimagewithcapinsets:insets];

IOS6 after uiedgeinsets insets = Uiedgeinsetsmake (image.size.height * 0.8f,image.size.width * 0.5f, 40, 40);

image = [Image resizableimagewithcapinsets:insets Resizingmode:uiimageresizingmodestretch];

Here are the explanations for use:

/**

*-(UIImage *) Stretchableimagewithleftcapwidth: (Nsinteger) leftcapwidth topcapheight: (Nsinteger) topcapheight;

*

* Leftcapwidth represents the left end cover width, topcapheight represents the top cover height. The system automatically calculates the right end cover width (rightcapwidth) and the bottom cover height (bottomcapheight)

* The algorithm is as follows:

* Width for picture widths rightcapwidth = width-leftcapwidth-1;

* Height for picture altitude bottomcapheight = height-topcapheight-1

*

* After calculation, you will find that the middle of the stretchable area is only 1x1

*

* Stretchwidth is the width of the middle stretchable area stretchwidth = Width-leftcapwidth-rightcapwidth = 1;

* Stretchheight is the height of the middle stretchable area stretchheight = Height-topcapheight-bottomcapheight = 1;

*

* Therefore, using this method will only stretch the image in the middle of the 1x1 area, and will not affect the edges and corners.

*/

/**

*-(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets

* This method only receives a parameter of type uiedgeinsets, you can specify the left, right, top and bottom of the left cover, the width of the end cap, the height of the cap, the height of the bottom cover, respectively.

* */

/**

*-(UIImage *) Resizableimagewithcapinsets: (uiedgeinsets) capinsets Resizingmode: (uiimageresizingmode) ResizingMode

Comparing the methods in iOS5.0, only one uiimageresizingmode parameter is used to specify the pattern of the extrusion: Uiimageresizingmodestretch: extrude mode, fills the picture by stretching uiedgeinsets the specified rectangular area Uiimageresizingmodetile: Tile mode, fills the picture by repeating the uiedgeinsets specified rectangular area

**/

Picture stretching of the above content reference article "ios Picture stretching skills" is very good, suggest you look more.

4. How to evoke your own browser (Safari) in iOS

is also a simple code, this is known to know, do not know is scratching it

Nsurl *url = [Nsurl urlwithstring:urlstr]; [[UIApplication sharedapplication] openurl:url];

5. Invoke the phone interface in iOS

The implementation of the phone interface within the app is a result of finding a lot of data (secure, and you can return to the app when you've dialed)

The way to do this is to use UIWebView to load the phone, which is now legal and the APP store is allowed to pass.

Nsurl *phoneurl = [Nsurl urlwithstring:[nsstring stringwithformat:@ "tel:%@", newphonestring]];

if (_phonecallwebview) {

[_phonecallwebview loadrequest:[nsurlrequest Requestwithurl:phoneurl];

}

However, if you use this method below, auditing may not be allowed [

[UIApplication sharedapplication] openurl:phoneurl];

6. How IOS calls the map

The app calls the third-party app inside, and here's a detailed article "iOS implementation opens third-party map app in app for navigation"

-the app calls the map and detects if the map app is already installed on the user's phone.

We often use the map app: Gold, Baidu, foreign: Google (Google map). Of course, there are Apple's own map, with the release of iOS10, Apple Maps This piece also has a great improvement and progress.

When I use the Xcode emulator, I'm prompted:

1.-canopenurl:failed for URL: "iosamap://"-Error: "(null)". The reason for this is that there is no high-D map on the simulator.

2.-canopenurl:failed for URL: "comgooglemaps://"-Error: "The This app isn't allowed to query for scheme comgooglemaps". The reason is: lsapplicationqueriesschemes my own sloppy set into a dictionary type.

First of all, it is iOS9 that we need to add a whitelist to the info.plist when we want to jump to other software inside the app.

The method is: Add the Key:lsapplicationqueriesschemes type to: Array in Info.plist.

The value of the gold, Baidu, and Google are filled in: **iosamap**|**baidumap**|**comgooglemaps**

Image:

As for the Urlscheme and appname in the code below

is to add URL Scheme in info.plist URL types (URL schemes is an array that allows the app to define multiple URL schemes. ) and URL identifier (it is recommended to use reverse domain name method to ensure the uniqueness of the name, such as Com.yourApp.www)

The picture is as follows:

Here is the specific code:

__block nsstring *urlscheme = urlscheme;

__block nsstring *appname = appName;

__block cllocationcoordinate2d coordinate = self.coordinate;

Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "select Map" Message:nil PreferredStyle: Uialertcontrollerstyleactionsheet];

Apple's own maps don't need to be judged

Uialertaction *action = [uialertaction actionwithtitle:@ "Apple Maps" Style:uialertactionstyledefault handler:^ ( Uialertaction *action) {

Mkmapitem *currentlocation = [Mkmapitem mapitemforcurrentlocation];

Mkmapitem *tolocation = [[Mkmapitem alloc] Initwithplacemark:[[mkplacemark alloc] Initwithcoordinate:coordinate Addressdictionary:nil]];

[Mkmapitem openmapswithitems:@[currentlocation, Tolocation] launchoptions:@{

Mklaunchoptionsdirectionsmodekey:mklaunchoptionsdirectionsmodedriving,mklaunchoptionsshowstraffickey: [NSNumber Numberwithbool:yes]}];

}];

[Alert addaction:action];

Judge Baidu Map

if ([[[UIApplication sharedapplication] canopenurl:[nsurl urlwithstring:@ "baidumap://"]])

{Uialertaction *action = [uialertaction actionwithtitle:@ "Baidu map" Style:uialertactionstyledefault handler:^ (UIAlertA Ction *action) {

NSString *urlstring = [[NSString stringwithformat:@] baidumap://map/direction?origin={{my location}}&destination= Latlng:%f,%f|name= destination &mode=driving&coord_type=gcj02 ", Coordinate.latitude, Coordinate.longitude] Stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:urlstring]];

}];

[Alert addaction:action];

}

Judging the map of the German

if ([[[UIApplication sharedapplication] canopenurl:[nsurl urlwithstring:@ "iosamap://"]])

{

Uialertaction *action = [uialertaction actionwithtitle:@ "German map" Style:uialertactionstyledefault handler:^ ( Uialertaction *action) {

NSString *urlstring = [[NSString stringwithformat:@] iosamap://navi?sourceapplication=%@&backscheme=%@&lat= %f&lon=%f&dev=0&style=2 ", Appname,urlscheme,coordinate.latitude, Coordinate.longitude] Stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:urlstring]]; }];

[Alert addaction:action];

}

Judging Google Maps

if ([[[UIApplication sharedapplication] canopenurl:[nsurl urlwithstring:@ "comgooglemaps://"]]) {

Uialertaction *action = [uialertaction actionwithtitle:@ "Google Maps" Style:uialertactionstyledefault handler:^ ( Uialertaction *action) {

NSString *urlstring = [[NSString stringwithformat:@] comgooglemaps://?x-source=%@&x-success=%@&saddr=& Daddr=%f,%f&directionsmode=driving ", Appname,urlscheme,coordinate.latitude, Coordinate.longitude]                      Stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; [[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:urlstring]];

}];

[Alert addaction:action];

}

Uialertaction *action = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil]; [Alert addaction:action];

[Self Presentviewcontroller:alert animated:yes completion:^{

}];

}

(IOS) Project summary-Various problems and workarounds encountered in the project

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.