This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//return an array of objects according to key, value, or key and value matching | |
function getObjects(obj, key, val) { | |
var objects = []; | |
for (var i in obj) { | |
if (!obj.hasOwnProperty(i)) continue; | |
if (typeof obj[i] == 'object') { | |
objects = objects.concat(getObjects(obj[i], key, val)); | |
} else | |
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not) | |
if (i == key && obj[i] == val || i == key && val == '') { // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// answer get from: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios | |
// usage example: drawImageIOSFix(context, img, 0, 0, file.width, file.height, 0,0, width, height); | |
/** | |
* Detecting vertical squash in loaded image. | |
* Fixes a bug which squash image vertically while drawing into canvas for some images. | |
* This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel | |
* | |
*/ | |
function detectVerticalSquash(img) { | |
var iw = img.naturalWidth, ih = img.naturalHeight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)applicationDidBecomeActive:(UIApplication *)application | |
{ | |
NSDate* end = [NSDate date]; | |
NSTimeInterval distanceBetweenDates = [self.current timeIntervalSinceDate:end]; | |
//if time is more than LOCK_DISPLAY_TIME(30s) | |
if (fabs(distanceBetweenDates) > LOCK_DISPLAY_TIME) | |
{ | |
UIViewController *root = [UIApplication sharedApplication].keyWindow.rootViewController; | |
while (root.presentedViewController) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://stackoverflow.com/questions/12445190/dismissmodalviewcontrolleranimated-deprecated | |
[self presentViewController:xxViewController animated:NO completion:nil]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. init with storyboard | |
//@"xxViewController" 这个值需要在storyboard中indetity inspector的storyboard ID相同 | |
//这种初始化可以带入storyboard的segue | |
xxViewController *xxViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"xxViewController"]; | |
// 2. init directly | |
aaViewController *aaViewController = [[aaViewController alloc] init]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// human.h: | |
#import <Foundation/Foundation.h> | |
@interface Human : NSObject | |
{ | |
int age; | |
NSString *name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//use other controller push to navigation controller | |
YourViewController *yourViewController = [[YourViewController alloc] init]; | |
yourViewController.title = @"TestTitle"; | |
[self.navigationController pushViewController:yourViewController animated:YES]; | |
[yourViewController release]; | |
// set current navigation title | |
self.navigationController.navigationBar.topItem.title = @"title 4 testing"; |