iOS tips Finishing

Source: Internet
Author: User

1 use of random numbers

References to header files
#import <time.h>
#import <mach/mach_time.h>

Use of Srandom ()
Srandom ((unsigned) (Mach_absolute_time () & 0xFFFFFFFF));

Call random numbers directly using random ()

2 Rotate the image in Uiimageview

float rotateangle = M_PI;
Cgaffinetransform transform =cgaffinetransformmakerotation (rotateangle);
Imageview.transform = transform;

The above code rotates ImageView, the angle is rotateangle, the direction can own test Oh!


3 How to set the rotation point in quartz

Uiimageview *imageview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Bg.png"];
ImageView.layer.anchorPoint = Cgpointmake (0.5, 1.0);

This is to set the rotation point to the bottom middle. Remember to be supported in Quartzcore.framework.

4. Create a. plist file and store

NSString *errordesc; Used to store error messages
Nsmutabledictionary *rootobj = [Nsmutabledictionary dictionarywithcapacity:4]; Nsdictionary, NSData and other files can be converted directly to plist file
Nsdictionary *innerdict;
NSString *name;
Player *player;
Nsinteger Saveindex;

for (int i = 0; i < [Playerarray count]; i++) {
Player = nil;
Player = [Playerarray objectatindex:i];
if (player = = nil)
Break
Name = player.playername;//this "Player1" denotes the player name could also is the computer name
Innerdict = [self getallnodeinfotodictionary:player];
[Rootobj setobject:innerdict Forkey:name]; This ' Player1 ' denotes the person who start this game
}
Player = nil;
NSData *plistdata = [nspropertylistserialization datafrompropertylist: (ID) rootobj FORMAT:NSPROPERTYLISTXMLFORMAT_V1 _0 errordescription:&errordesc];

The red part can be ignored, just add a bit of content to rootobj. This plistdata to create a good plist file, with its WriteToFile method can be written as a file. Here's the code:

/* Get the file storage location on your mobile device */
NSString *documentspath = [self getdocumentsdirectory];
NSString *savepath = [Documentspath stringbyappendingpathcomponent:@ "Save.plist"];

/* Save File */
if (plistdata) {
[Plistdata Writetofile:savepath Atomically:yes];
}
else {
NSLog (ERRORDESC);
[Errordesc release];
}

-(NSString *) getdocumentsdirectory {
Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
return [Paths objectatindex:0];
}

4 Read plist file and convert to Nsdictionary

NSString *documentspath = [self getdocumentsdirectory];
NSString *fullpath = [Documentspath stringbyappendingpathcomponent:@ "Save.plist"];
nsmutabledictionary* plistdict = [[Nsmutabledictionary alloc] initwithcontentsoffile:fullpath];

5 Reading general document files

NSString *tmp;
Nsarray *lines; /* Convert the file to a line of */
lines = [[NSString stringwithcontentsoffile:@ "TestFileReadLines.txt"]
componentsseparatedbystring:@ "/n"];

Nsenumerator *nse = [lines objectenumerator];

Read the content in <>
while (TMP = [NSE Nextobject]) {
NSString *stringbetweenbrackets = nil;
Nsscanner *scanner = [Nsscanner scannerwithstring:tmp];
[Scanner scanuptostring:@ "<" Intostring:nil];
[Scanner scanstring:@ "<" Intostring:nil];
[Scanner scanuptostring:@ ">" intostring:&stringbetweenbrackets];

NSLog ([stringbetweenbrackets description]);
}

6 Hidden Navigationbar 

[Self. Navigationcontroller setnavigationbarhidden:yes Animated:yes];

Uikeyboardwillshownotification

Uikeyboardwillhidenotification

Uikeyboard ...

IOS 5 has added some new

Uikeyboarddidchangeframenotification (would)

In general, the first two events can already be done. Adding the Nsnotification parameter to your event handling method will get you something more:

  1. -(void) Keyboardwillshow: (nsnotification *) Notification
  2. {
  3. Cgpoint begincentre = [[[Notification UserInfo] Valueforkey:uikeyboardcenterbeginuserinfokey]   Cgpointvalue];
  4. Cgpoint endcentre = [[[Notification UserInfo] Valueforkey:uikeyboardcenterenduserinfokey] Cgpointvalue];
  5. CGRect keyboardbounds = [[[Notification UserInfo] Valueforkey:uikeyboardboundsuserinfokey] Cgrectvalue];
  6. CGRect keyboardframes = [[[Notification UserInfo] Valueforkey:uikeyboardframeenduserinfokey] cgrectvalue  ];
  7. Uiviewanimationcurve animationcurve = [[[Notification UserInfo] valueforkey:  Uikeyboardanimationcurveuserinfokey] Intvalue];
  8. Nstimeinterval animationduration = [[[Notification UserInfo] valueforkey:  Uikeyboardanimationdurationuserinfokey] Doublevalue];
  9. }

If you want to use the keyboard height and width in the program, never try to manually specify, dynamic access is also very simple and must be accurate, there will be no keyboard blocking the input box problem.

You can use these parameters to make the animation and the keyboard consistent. Let's say you want to put a control on a window and want it to interact like a keyboard,

If you simply do a downward offset animation is not very good, because you also want to consider from the navigation bar pop out, this time the keyboard animation is

Offset on the x-axis, the frame you get with Uikeyboardframeenduserinfokey can do it very accurately.

If you don't want to use the default keyboard for some special fields, instead of a picker like picker, you just need to set up Inputview and replace the keyboard with your custom view, if you want to add a view to the keyboard, like toolbar, Then you can not control the location of the toolbar, only need to set the Inputaccessoryview on the line, this value is nil, the setting of the view will be in your control to become the first responder when it appears above the Inputview.



iOS tips Finishing

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.