| 123456789101112131415161718192021222324252627282930313233343536373839 | // 定義名稱 define key #define kIsActive @"isActive" #define kUserName @"userName" // 讀取資料 -(void)loadInfo { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSLog(@"Name : %@", [defaults stringForKey:kUserName]); NSLog(@"isActive : %@", ([defaults boolForKey:kIsActive] ? @"YES" : @"NO")); } // 儲存資料 -(void)saveInfo { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *userName = @"Hank"; BOOL isActive = YES; [defaults setObject:userName forKey:kUserName]; [defaults setBool:isActive forKey:kIsActive]; } // 清除資料 -(void)clearInfo { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults removeObjectForKey:kUserName]; [defaults removeObjectForKey:kIsActive]; } // 執行 - (void)viewDidLoad { [super viewDidLoad]; [self saveInfo]; [self loadInfo]; [self clearInfo]; [self loadInfo]; } |
- May 30 Sat 2015 12:01
-
[轉][iOS Dev] NSUserDefaults Save/Read/Clear 儲存/讀取/清除 速記 使用者記錄 使用者設定 SharedPreferences
- May 30 Sat 2015 11:54
-
ios uiview animate frame
delay:1.0
options: UIViewAnimationCurveEaseOut
animations:^{
self.basketTop.frame = basketTopFrame;
self.basketBottom.frame = basketBottomFrame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
[UIView animateWithDuration:0.6f
- May 30 Sat 2015 11:50
-
常用數學函數 (轉貼) ios objc
Math functions
double pow ( double, double ) - power of
NSLog(@"%.f", pow(3,2) ); //result 9
NSLog(@"%.f", pow(3,3) ); //result 27
double sqrt( double ) - square root
NSLog(@"%.f", sqrt(16) ); //result 4
NSLog(@"%.f", sqrt(81) ); //result 9
double ceil ( double ) - if the argument has any decimal part, returns the next bigger integer
NSLog(@"res: %.f", ceil(3.000000000001)); //result 4
NSLog(@"res: %.f", ceil(3.00)); //result 3
double floor ( double ) - removes the decimal part of the argument
NSLog(@"res: %.f", floor(3.000000000001)); //result 3
NSLog(@"res: %.f", floor(3.9999999)); //result 3
double round ( double ) - rounds the argument
NSLog(@"res: %.f", round(3.5)); //result 4
NSLog(@"res: %.f", round(3.46)); //result 3
NSLog(@"res: %.f", round(-3.5)); //NB: this one returns -4
double fmin ( double, double ) - returns the smaller argument
NSLog(@"res: %.f", fmin(5,10)); //result 5
double fmax ( double, double ) - returns the bigger argument
NSLog(@"res: %.f", fmax(5,10)); //result 10
double fabs( double ) - returns the absolute value of the argument
NSLog(@"res: %.f", fabs(10)); //result 10
NSLog(@"res: %.f", fabs(-10)); //result 10
Few math constants
As found in the math.h
#define M_E 2.71828182845904523536028747135266250 /* e */
#define M_LOG2E 1.44269504088896340735992468100189214 /* log 2e */
#define M_LOG10E 0.434294481903251827651128918916605082 /* log 10e */
#define M_LN2 0.693147180559945309417232121458176568 /* log e2 */
#define M_LN10 2.30258509299404568401799145468436421 /* log e10 */
#define M_PI 3.14159265358979323846264338327950288 /* pi */
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
#define M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
#define M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
#define M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
#define M_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */
#define M_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */
#define M_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
#define MAXFLOAT ((float)3.40282346638528860e+38)
- May 30 Sat 2015 11:48
-
[轉] 2015最新AppStore上架流程 ios
來源:http://blog.csdn.net/baidu_21172753/article/details/42678487
1.进入 https://developer.apple.com,选择Member Center,进去后点击iTunes Connect,输入账号密码。进去后,点击我的APP,然后点击左侧的加号,就可以创建应用了
2.创建应用需要填写必要信息
- May 20 Wed 2015 10:59
-
How can I disable the UITableView selection highlighting? 關閉 UITableView 點擊 高亮 使失效
- May 20 Wed 2015 10:51
-
[轉]iOS並發編程NSThread、Grand Central Dispatch、Operation Queue 多執行續
在移動和桌面操作系統中,蘋果提供了相同的並發編程API。 NSThread、Grand Central Dispatch(GCD)、NSOperationQueue
- May 20 Wed 2015 10:49
-
Is there a way to pause SKActions? 暫停 SKScreen 遊戲 IOS Spritekit
Paused
A
Boolean value that indicates whether the view’s scene animations are paused.@property(getter=isPaused, nonatomic) BOOL paused
Discussion If the value is YES, then the scene’s content is fixed on screen. No actions are executed and no physics simulation is performed."
- May 20 Wed 2015 09:50
-
Proper way to exit iPhone application? 離開 iphone app 關閉app
Have you tried exit(0)?
Alternatively, [[NSThread mainThread] exit], although I have not tried that it seems like the more appropriate solution.
On the iPhone there is no concept of quitting an app. The only action that should cause an app to quit is touching the Home button on the phone, and that's not something developers have access to.
According to Apple, your app should not terminate on its own. Since the user did not hit the Home button, any return to the Home screen gives the user the impression that your app crashed. This is confusing, non-standard behavior and should be avoided.
After some tests, I can say the following:
- using the private interface :
[UIApplication sharedApplication]will cause the app looking like it crashed, BUT it will call- (void)applicationWillTerminate:(UIApplication *)applicationbefore doing so; - using
exit(0);will also terminate the application, but it will look "normal" (the springboard's icons appears like expected, with the zoom out effect), BUT it won't call the- (void)applicationWillTerminate:(UIApplication *)applicationdelegate method.
My advice:
- Manually call the
- (void)applicationWillTerminate:(UIApplication *)applicationon the delegate. - Call
exit(0);.
Apple says not to use exit due to "Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen"developer.apple.com/library/ios/#qa/qa2008/qa1561.html – Micky Duncan Sep 5 '12 at 22:20 |
- May 20 Wed 2015 09:48
-
how to add particles using SpriteKit in iOS7 加入 粒子 IOS SpriteKit
First, you have to create a SKEmitterNode with your particle:
NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
SKEmitterNode *myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
- Apr 17 Fri 2015 16:35
-
Horizontally mirror a SKSpriteNode texture 鏡像 圖片 左右相反
- Apr 17 Fri 2015 16:30
-
Two or more collisions at same time in Sprite Kit 同時多個碰撞
Declare an instance variable called NSMutableArray *_contactQueue; Add the contacts to the array:
-(void) didBeginContact:(SKPhysicsContact*)contact
{[_contactQueue addObject:contact];}
- Apr 17 Fri 2015 16:28
-
在iOS上present一个半透明的viewController 透明view controller