[resolved] how to fade default.png?

Any suggestions on where to start with fading the default.png? I’m not new to iOS development but am new to OF. Any suggestions would be appreciated.

// Edit - This is what worked for me. The URL is where I started, and the code below is how I implemented into my app. It’s not perfect but it’s a start.

http://www.ericd.net/2009/07/iphone-make-your-defaultpng-sexy.html
Add to ofxiPhoneAppDelegate.h & .mm in you app’s \ofxiPhone\srv folder.

** - 1st Part - ofxiPhoneAppDelegate.h**
@interface ofxiPhoneAppDelegate : NSObject {
UIWindow *window;
//MSARootViewController *viewController;
UIImageView *splashView;

NSTimer *timer;
float targetFrameRate;

EAGLView *glView;

uint64_t frameLength; // nanoseconds between successive frames at targetFrameRate
bool killThread;
bool loopInThreadIsEnabled;

NSLock *glLock;
}

-(void) receivedRotate:(NSNotification*)notification;
-(void) setFrameRate:(float)frameRate;
-(void) enableLoopInThread;
-(EAGLView*) getGLView;

-(void)lockGL;
-(void)unlockGL;

  • (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;

@end

- ofxiPhoneAppDelegate.h

  • (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [splashView removeFromSuperview];
    [splashView release];
    }

-(void) applicationDidFinishLaunching:(UIApplication *)application {
static ofEventArgs voidEventArgs;
ofLog(OF_LOG_VERBOSE, “applicationDidFinishLaunching() start”);

// create an NSLock for GL Context locking
glLock = [[NSLock alloc] init];

// create fullscreen window
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// create the OpenGL view and add it to the window
glView = [[EAGLView alloc] initWithFrame:[[UIScreen mainScreen] bounds] pixelFormat:GL_RGB565_OES depthFormat:GL_DEPTH_COMPONENT16_OES preserveBackbuffer:NO];
[window addSubview:glView];
// [glView release]; // do not release, incase app wants to removeFromSuper and add later

//[window addSubview:viewController.view]; // JW - This was part of the “fade default”, could be nessecary…

// make window active
[window makeKeyAndVisible];

// Make this interesting.
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:@“Default.png”];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
splashView.frame = CGRectMake(0, 0, 320, 480);
[UIView commitAnimations];

//----- DAMIAN
// set data path root for ofToDataPath()
// path on iPhone will be ~/Applications/{application GUID}/openFrameworks.app/data
// get the resource path for the bundle (ie ‘~/Applications/{application GUID}/openFrameworks.app’)
NSString *bundle_path_ns = [[NSBundle mainBundle] resourcePath];
// convert to UTF8 STL string
string path = [bundle_path_ns UTF8String];
// append data
//path.append( “/data/” ); // ZACH
path.append( “/” ); // ZACH
ofLog(OF_LOG_VERBOSE, "setting data path root to " + path);
ofSetDataPathRoot( path );
//-----

// zero targetFrameRate (to see if user setes it in setup()
targetFrameRate = -1;

iPhoneSetOrientation(OFXIPHONE_ORIENTATION_PORTRAIT);

// call testApp::setup()
ofGetAppPtr()->setup();
#ifdef OF_USING_POCO
ofNotifyEvent( ofEvents.setup, voidEventArgs );
ofNotifyEvent( ofEvents.update, voidEventArgs );
#endif

// if user didn’t set framerate in setup(), default to 60
if(targetFrameRate == -1) [self setFrameRate:60];

// show or hide status bar depending on OF_WINDOW or OF_FULLSCREEN
//[[UIApplication sharedApplication] setStatusBarHidden:(iPhoneGetOFWindow()->windowMode == OF_FULLSCREEN) animated:YES];

// clear background
glClearColor(ofBgColorPtr()[0], ofBgColorPtr()[1], ofBgColorPtr()[2], ofBgColorPtr()[3]);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// From Robert Carlsen // THREAD MOD
if(loopInThreadIsEnabled) {
[NSThread detachNewThreadSelector:@selector(timerLoopThreaded:) toTarget:self withObject:nil];
}

// Listen to did rotate event
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(receivedRotate:)
name: UIDeviceOrientationDidChangeNotification
object: nil];
}

Hi.

i use ofxFadable addon .

Download ofxFadable addon from here: http://code.google.com/p/ruicode/downlo-…-%20001.zip

Dorald - Thank you!

Actually, I’m not sure how ofxFadable helps here?

For me, the issue is the brief screen blank that occurs when you switch to the glView. It breaks the transition from Default.png to your fading (of) image.

That’s why I think Jason was on the right track. I’m using Jason’s method and it’s working like a charm on iphone 4 and ipad.

To get the code to work on my version of openframeworks, I had to remove the “window” declare in the .h file. And I just used screenBounds for the new view frame size.

This had been something I’ve wanted to do for a while, so thanks Jason!

DavidDC - You’re welcome!

Speaking of iPhone & iPad, if anyone wants me to show how to determine whether it’s iPhone or iPad just let me know and I’ll add it above.

  
	splashView = [[UIImageView alloc] initWithFrame:screenBounds];  
	  
	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  
		splashView.image = [UIImage imageNamed:@"Default-iPad.png"];  
	else  
		splashView.image = [UIImage imageNamed:@"Default.png"];  
  

Obviously Default-iPad.png needs to be in your plist under UILaunchImageFile~ipad.

[edit] Oh, sorry - misread your offer as a question! Still need the retina display code though…

No worries! :slight_smile:

Here’s how I did the iPad/iPhone difference. Mine’s a little more bulky but, keeping with my original code:

  
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  
	{  
		// The device is an iPad.  
		splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 768, 1024)];  
		splashView.image = [UIImage imageNamed:@"Default-Portrait.png"];  
		[window addSubview:splashView];  
		[window bringSubviewToFront:splashView];  
		[UIView beginAnimations:nil context:nil];  
		[UIView setAnimationDuration:3.0];  
		[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];  
		[UIView setAnimationDelegate:self];   
		[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];  
		splashView.alpha = 0.0;  
		splashView.frame = CGRectMake(0, 0, 768, 1024);  
		[UIView commitAnimations];  
	}  
	else  
	{  
		// The device is an iPhone or iPod touch.  
		splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];  
		splashView.image = [UIImage imageNamed:@"Default@2x.png"];  
		[window addSubview:splashView];  
		[window bringSubviewToFront:splashView];  
		[UIView beginAnimations:nil context:nil];  
		[UIView setAnimationDuration:3.0];  
		[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];  
		[UIView setAnimationDelegate:self];   
		[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];  
		splashView.alpha = 0.0;  
		splashView.frame = CGRectMake(0, 0, 320, 480);  
		[UIView commitAnimations];  
	}  

This is great!
I’ve been able to implement this, but I’m running into an issue for a landscape based app.
In landscape mode on the iPad, it could be launching in landscapeLeft or landscapeRight, which the window and glView is aware of, but for some reason the splashView doesn’t follow the same orientation.

i’ve tried

  
	if([UIDevice currentDevice].orientation==UIDeviceOrientationLandscapeRight)	  
	{  
		splashView.transform = CGAffineTransformMakeRotation(3.14159265); //rotation in radians  
	}  

which sort of works. the problem is when the ipad launches lying flat. Then the device orientation is unknown. So it only works if the iPad is clearly tilted in an orientation on launch.

i’ve also tried

  
	if(	[[window rootViewController] interfaceOrientation]==UIInterfaceOrientationLandscapeLeft)  
      
	{  
		splashView.transform = CGAffineTransformMakeRotation(3.14159265);   
	}  

which doesn’t seem to work.

and finally

  
    if([[UIApplication sharedApplication] statusBarOrientation]==UIInterfaceOrientationLandscapeLeft)  
	{  
		splashView.transform = CGAffineTransformMakeRotation(3.14159265);   
	}  

which doesn’t seem to do anything either.

any other suggestions would be super helpful. I’m probably going about this in the wrong way.

[quote author=“cheewee2000”]This is great!
I’ve been able to implement this, but I’m running into an issue for a landscape based app.
In landscape mode on the iPad, it could be launching in landscapeLeft or landscapeRight, which the window and glView is aware of, but for some reason the splashView doesn’t follow the same orientation.[/quote]

Without completely reviewing your post - have you included the appropriate launch/default files for landscape? You’ll also need to reference via the plist file and possibly in your code too… I haven’t done this yet but if you get stuck send me a private message and I will check it out.

Refer to this:
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html%23//apple-ref/doc/uid/TP40006556