All 4 States of Stack Transitions for iOS

https://github.com/mevdev/View-Controllers-4-State-Transitions

Animate or do special things for each of the 4 state transitions of a View Controller

This fills a need for when I want to do different animations depending on which transition a View Controller is happening.

We’re going to do different animations when View Controllers are pushed or popped from the stack. We’ll start with 4 states, being ‘pushed’, ‘popped’, ‘put back’ and ‘popped to’.

‘Pushed On’ is when you add a new View Controller to the stack and it is now visible.
‘Popped’ is when your view controller was visible and it is transitioning to be gone.
‘Put Back’ is when your view controller was visible and another one is going on top of it.
‘Popped to’ is when your view controller was in the stack and the one on top was just popped.
If you want to slow things down do ‘Slow Animations’ ⌘-T or in the menu Debug->Slow Animations.

FlurryAds Interstitial ads with Cocos2d v3

This is my first foray into ad-supported territory. I am really liking Cocos2d and recently my focus has been on the newest v3 (currently rc4). In this tutorial we will put up some interstitial ads for iphone and/or ipad.

Cocos2d v3 has a great new installer. It gives you a couple options in XCode. It’s even compatible with the latest XCode (5.1) and ARC.

-all those frameworks.
AdSupport.framework (Mark as Optional to support < iOS 6.0)
CoreGraphics.framework
Foundation.framework
MediaPlayer.framework
Security.framework
StoreKit.framework (Mark as Optional to support < iOS 6.0)
SystemConfiguration.framework
UIKit.framework

//do the first delegate stuff
In the AppDelegate.h go into the
-(BOOL) application: didFinishLaunchingWithOptions:

[Flurry setCrashReportingEnabled:YES];
[Flurry startSession:@"YOUR_API_KEY"];
[FlurryAds enableTestAds:YES];

Continue reading

Easy way to see (and debug) UILocalNotifications

It doesn’t take a lot of code to create a UILocalNotification but when you have multiple of them and you’re doing a lot of calendar math and things start getting hairy. To demystify that experience I created a project with a UITableViewController that prints out all of the current UILocalNotifications.

We’ll create 3 local notifications 1 minute apart for the next 3 minutes with these calls:

   [self createLocalNoticationAt:[[NSDate date] dateByAddingTimeInterval:60] withTitle:@"Every Minute 1!"];
    [self createLocalNoticationAt:[[NSDate date] dateByAddingTimeInterval:120] withTitle:@"Every Minute 2!"];
    [self createLocalNoticationAt:[[NSDate date] dateByAddingTimeInterval:180] withTitle:@"Every Minute 3!"];

Continue reading

Detect the end of a UILongPressGestureRecognizer

I am coding the previous/next buttons of a music player. I need these UIButtons to have dual purpose.

1. Tap – Previous/Next song
2. Long Press – Seek

That works, but what got me was that I didn’t know when the end of the long press was so I never knew when to stop seeking. I tried to attach an action to the UIButton on the UIControlEventTouchCancel event, but that is not correct.

This is my setup code:

    gestureSeekBackward = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(seekBackward:)];
    gestureTapBackward = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(previousSong:)];
    gestureTapBackward.numberOfTapsRequired = 1;
    [backwardButton addGestureRecognizer:gestureSeekBackward];
    [backwardButton addGestureRecognizer:gestureTapBackward];

What I needed to do was check whether the state is ended for the seek gesture. Continue reading

Chaining UIView animations with blocks

I really love UIView animations. They are so simple and elegant. This little chain I will make will fade in a UIView (or descendant) from the left, wait a moment, then fade out to the left. In general you can animate all of these properties: frame,bounds,center,transform,alpha,backgroundColor,and contentStretch in a UIView animation block.

For this example I created a single view application and put a UIImageView in the middle of the screen. UIImageView is a direct descendant of UIView so it is perfect for this exercise.
UIImageView
Continue reading

UITableView Disclosure Indicator on a UIButton

Although it is non-standard. I needed to match pixel-perfect to a design, so I created this. On a UITableView it is called ‘Disclosure Indicator’ as opposed to the one available from UIButton which is ‘Detail Disclosure’.

table_indicator

It is 50×80 with a transparent background. Use this image on top of a button or UIImageView. Resize it to whatever size you’d like your button to be. Apple recommends a hit target of no less than 40×40. I sized it to 10×16 in my storyboard, but I am using a transparent button overlay so the size doesn’t matter.
Continue reading

Configure a UIScrollView entirely in Storyboard with Interface Builder

Usually even if you drop in a UIScrollView, put a UIView into that and align them correctly it still does not work. Why? It’s UIScrollView.contentSize. Now we can easily do this in code, but it is also easily accomplished in Interface Builder.

The first thing I’ve done is drop in a UIScrollView, pop a UIView inside of it and then populate my controls into said UIView. We can verify this by looking at the hierarchal view.
UIView inside UIScrollView
Continue reading