Summary of some small technologies in iPhone Development

Source: Internet
Author: User
Reference of the random number header file # import time. h # import Mach/mach_time.h srandom () Use srandom (unsigned) (mach_absolute_time () 0 xffffffff); Use random () to call Random Number 2 rotate the image in uiimageview
1. Use of random numbers

Header file reference
# Import <time. h>
# Import <Mach/mach_time.h>

Use of srandom ()
Srandom (unsigned) (mach_absolute_time () & 0 xffffffff ));

Directly use random () to call random numbers

2. Rotate the image in uiimageview

Float rotateangle = m_pi;
Cgaffinetransform transform = cgaffinetransformmakerotation (rotateangle );
Imageview. Transform = transform;

The above code rotates the imageview, and the angle is rotateangle. You can test the direction yourself!

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 );

Set the rotation point to the center of the bottom. Remember that it is only supported in quartzcore. framework.

4. create and store the. plist File

Nsstring * errordesc; // used to store error messages
Nsmutabledictionary * rootobj = [nsmutabledictionary dictionarywithcapacity: 4]; // nsdictionary, nsdata, and other files can be directly converted to plist files.
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 cocould also be 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 adding a bit of content to the rootobj. This plistdata is a created plist file, which can be written as a file using its writetofile method. The following code is used:

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

/* Save the 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 the plist file and convert it to nsdictionary.

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

5. Read general document files

Nsstring * TMP;
Nsarray * lines;/* convert a file to a row */
Lines = [[nsstring stringwithcontentsoffile: @ "testfilereadlines.txt"]
Componentsseparatedbystring: @ "/N"];

Nsenumerator * neuron = [Lines objectenumerator];

// Read the content in <>
While (TMP = [neuron nextobject]) {
Nsstring * stringbetweenbrackets = nil;
Ns‑* token = [ns‑scannerwithstring: TMP];
[Export scanuptostring: @ "<" Export string: Nil];
[Export scanstring: @ "<" Export string: Nil];
[Export scanuptostring: @ ">" Export string: & stringbetweenbrackets];

Nslog ([stringbetweenbrackets description]);
}

For reading and writing files, there are also supplements. It is now. Random Numbers and file reads and writes are often used in game development. So I put some content here to share with you and record it for ease of searching.

6 hide navigationbar
[Self. navigationcontroller setnavigationbarhidden: Yes animated: Yes];

You can use it in the viewcontroller you want to hide.

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.