Skip to content

Instantly share code, notes, and snippets.

View kenshin03's full-sized avatar

Kenny Tang kenshin03

View GitHub Profile
// 1. set up the intial view with the first Feed Item
- (void) initFeedsPageViewController {
...
FeedItem * firstFeedItem = self.feedItemsArray[0];
PSHCoverFeedPageViewController * currentPagePageViewController = [[PSHCoverFeedPageViewController alloc] init];
currentPagePageViewController.feedType = firstFeedItem.type;
currentPagePageViewController.messageLabelString = firstFeedItem.message;
@kenshin03
kenshin03 / gist:5494316
Created May 1, 2013 08:26
animating the bouncing "LIKE" image
- (void) likeFeed {
UIImageView * animatedLikeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coverfeed-like_button"]];
animatedLikeImageView.frame = CGRectMake(80.0f, 210.0f, 160.0f, 160.0f);
animatedLikeImageView.contentMode = UIViewContentModeScaleToFill;
self.animatedLikeImageView = animatedLikeImageView;
self.animatedLikeImageView.hidden = YES;
[self.view addSubview:self.animatedLikeImageView];
double delayInSeconds = .3;
@kenshin03
kenshin03 / gist:5494312
Created May 1, 2013 08:25
comments view controller
-(IBAction)commentButtonTapped:(id)sender {
if (self.commentsPostingView.hidden == YES){
if (self.commentsViewController != nil){
self.commentsViewController = nil;
[self.commentsViewController.view removeFromSuperview];
[self.commentsViewController removeFromParentViewController];
}
self.commentsViewController = [[PSHCommentsViewController alloc] init];
@kenshin03
kenshin03 / gist:5494256
Created May 1, 2013 08:03
ascync loading background image and extracting its background color with LEColorPicker
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (!self.imageURLString){
self.imageURLString = self.sourceAvartarImageURL;
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
}
UIImage * feedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageURLString]]];
dispatch_async(dispatch_get_main_queue(), ^{
self.backgroundImageView.alpha = 0.0f;
@kenshin03
kenshin03 / gist:5494243
Created May 1, 2013 07:59
stop animated background
- (void)stopAnimateBackground {
self.backgroundImageView.transform = CGAffineTransformIdentity;
[UIView setAnimationsEnabled:YES];
}
@kenshin03
kenshin03 / gist:5494240
Created May 1, 2013 07:58
Ken Burns effect on image view
- (void)animateBackground {
NSInteger randInt = arc4random()%3;
NSInteger translationX = 0;
NSInteger translationY = 0;
NSInteger scaleX = 0;
NSInteger scaleY = 0;
switch (randInt) {
@kenshin03
kenshin03 / gist:5487548
Created April 30, 2013 09:08
Home for iOS initial pod file
platform :ios, '6.1'
pod 'MagicalRecord', '~>2.1.0'
pod 'AFNetworking', '~>1.2.0'
@kenshin03
kenshin03 / gist:5487531
Created April 30, 2013 09:04
Magical Records save before refetching data
// save before refreshing data
[[NSManagedObjectContext MR_defaultContext] saveWithOptions:MRSaveSynchronously completion:^(BOOL success, NSError *error) {
NSArray * feedItemsArray = [FeedItem findAllSortedBy:@"createdTime" ascending:NO];
fetchFeedSuccess(feedItemsArray, nil);
}];
@kenshin03
kenshin03 / gist:5487495
Created April 30, 2013 08:55
Facebook Graph API request with ACAccountStore refer to https://gist.github.com/kenshin03/5487487 for the initAccount part
- (void) likeFeed:(NSString*)graphID {
InitAccountSuccessBlock successBlock = ^{
NSString * likeURLString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/likes", graphID];
NSURL * feedURL = [NSURL URLWithString:likeURLString];
SLRequest * request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:nil];
NSLog(@"request.URL: %@", request.URL);
request.account = self.facebookAccount;
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
@kenshin03
kenshin03 / gist:5487487
Created April 30, 2013 08:53
Facebook authentication with ACAccountType
NSDictionary * facebookOptions = @{ACFacebookAppIdKey:kPSHFacebookAppID,
ACFacebookPermissionsKey: @[@"email", @"publish_stream", @"read_stream", @"user_photos"],
ACFacebookAudienceKey:ACFacebookAudienceFriends};
ACAccountType * facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:facebookAccountType options:facebookOptions
completion: ^(BOOL granted, NSError *error) {
NSLog(@"granted: %i", granted);
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType];