I am building an app that has picture viewing capabilities. I have wrestled the UIScrollView beast to the ground (hope to post my scrollview knowledge RSN) and am now trying to duplicate some of the other visual effects of the iPhone photos app. specifically, when viewing an image, I would like to dissolve the controls and bars away.
I have a method that toggles visibility of the status bar, navigation bar, and tab bar, leaving just the scrollview with an image. The scrollview is full screen. I have a timer that fires 3 seconds after the user does something (single taps the screen, views the next image, etc.) and in the timerFired method, I call my method to turn off the bars. a single tap of the screen turns on the bars. here's the method to toggle the full screen state.
- (void)setFullScreen:(BOOL)fullScreen {
// reset the timer
[myTimer invalidate];
[myTimer release];
myTimer = nil;
// start animation section
[UIView beginAnimations:nil context:nil];
// toggle the status bar
[[UIApplication sharedApplication] setStatusBarHidden:fullScreen animated:YES];
[UIView setAnimationDuration:UINavigationControllerHideShowBarDuration];
CGFloat alpha = fullScreen ? 0.0 : 1.0;
// change the alpha to either 0 or 1 based on hiding or showing the bars
self.navigationController.navigationBar.alpha = alpha;
self.tabBarController.tabBar.alpha = alpha;
// do the animations!
[UIView commitAnimations];
// restart the timer after we show the bars
if (!fullScreen) {
myTimer = [[NSTimer timerWithTimeInterval:3.0 target:self selector:#selector(timerFired:) userInfo:nil repeats:NO] retain];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
}
}
This basically works, BUT, it doesn't look as good as the photos app. I am animating the alpha values as I believe that this looks more like the photos app instead of the using the hidden with Animation methods available. My problem is doing the same for the status bar.
my questions:
(1) is there a UIView for the the status bar?
(2) is there a way to change the alpha property of the status bar?
(3) is the statusbar in another UIWindow?
(4) is there another way to achieve this using "legal" methods (I need to put this app in the app store)?
I've dumped the windows property of the UIApplication and there was only 1 window and I've crawled the view hierarchy and there was not an obvious view for the status bar.
any ideas?
The status bar is created by SpringBoard itself, it is of class SBStatusBar (which IIRC inherits from UIWindow). It is not accessible to app store applications.
Related
I am new in iOS developement.When I press the stopwatch start button I want to display the timer like counter token effect.I have attached image for your reference.I have done to display secs and minutes but I dont know, How animate autoscroll effect? How can I do this?
When the counter is moving it shouldn't jump from one number to another number, instead it should move from one number to next number smoothly, just like the petrol pump meter. Thanks
I have done something like this before - this code is not necessarily clean, but it does the job.
You want to create twoUILabels in your .h file:
IBOutlet UILabel *figureLabel1;
IBOutlet UILabel *figureLabel2;
Then you want to create a BOOL so that we can tell which UILabel is visible to the user.
BOOL firstLabel;
So lets imagine that the initial label (showing the number 1) is figureLabel1 and the future UILabel to be displayed (showing the number 2) is figureLabel2. However when the counter adds one, then the figureLabel2 moves up and takes the figureLabel1's place. Then, while the figureLabel1 is hidden, it takes the place of figureLabel2 when figureLabel1 was visible.
See here:
// Check what label is showing
if (firstLabel == YES) {
// Following code the hide and move the figureLabel1
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate: self]; //or some other object that has necessary method
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
// Slowing fade out the figureLabel1
[figureLabel1 setAlpha:0];
// Move the figureLabel1 up and out of the way
[figureLabel1 setFrame:CGRectMake(20, 108, 287, 55)];
[UIView commitAnimations];
// Following code the show and move the figureLabel2
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
// Slowing fade in the figureLabel2
[figureLabel2 setAlpha:1];
// Move the figureLabel2 up and into position
[figureLabel2 setFrame:CGRectMake(20, 141, 287, 55)];
[UIView commitAnimations];
// Update BOOL for next label
firstLabel = NO;
} else {
// Exactly the same but opposite
}
As I said, this is not pretty but it shows the basic concept. All the best!
You need to manually scroll tableView instead of scrollToRowAtIndexPath because this animation uses its own timer interval and its very difficult or we can say impossible to change its time interval.
So, I am Implementing an API for such kind of problems and made a demo app for you with smooth scrolling as you want.
You need to use an outer timer that fires every 1 second and an internal timer that will fire every 0.03 sec as my tableRow Height is 30 I calculated internal timer interval as :---
Move 30 pixels for 1 sec , then
Move 1 pixel for 0.33 sec inside internal timer.
The Internal timer will invalidate and fire every 1 second as initialized within outer timer.
And internal timer will perform the movement of cell.
dial4 is a tableView
Have a look at my code.
#define rowHeight 30
-(void)startCounter
{
outertimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(snapCell) userInfo:nil repeats:YES];
}
-(void)stopCounter
{
[outertimer invalidate];
}
-(void)snapCell
{
NSLog(#"Initialize Internal timer %i",secLsb);
secLsb++;
if (secLsb==10) {
[dial4 setContentOffset:CGPointMake(0, 0) animated:NO];
secLsb=0;
NSLog(#"dial content offset y is %f",dial4.contentOffset.y);
}
[internaltimer invalidate];
internaltimer=[NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:#selector(automaticScroll)
userInfo:nil
repeats:YES];
}
-(void)automaticScroll
{
NSLog(#"val is & y ======== %f",dial4.contentOffset.y);
[dial4 setContentOffset:CGPointMake(dial4.contentOffset.x,dial4.contentOffset.y+1) animated:NO];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return rowHeight;
}
Have a look at Time Counter
From image it can be assume that you are trying to get an effect like count-down timer. Have a look at countdown timer here. It may helps you somehow.
Enjoy Programming !!
Refer both links for your output. It helps you
UIPickerView that looks like UIDatePicker but with seconds
and
How can I make my UIPickerView show labels after the selected value?
Thanks.
Several good ideas here so far, but I'll add another.
First, be sure to set the container view (your blue rectangle) to clip children, using the Clip Subviews checkbox in Interface Builder.
Second, add a set of child views with images of each numeral for each digit to be presented (4 * 10 = 40 child views in your case). Use tags in IB so you can easily access each one. Set the initial bounds to just below your bottom margin.
Call UIView animateWithDuration. In the animations block, set the new digit view's frame to appear in the clipped parent view's bounds, and set the old digit view's frame to just above the container's bounds. Since both view's frame changes are animated in the same block, this will create the effect of the new digit sliding up into place as the old digit slides out the top.
In the completion block, set the old digit's frame back to the original position below the container view.
With this approach, you can play with the duration and the timing curves, so that you cam emulate the pause that occurs with each digit fully displayed between transitions.
A similar approach can also be used with CALayer, or with sprites, but UIViews are lightweight, perform well, and easiest to assemble in Interface Builder.
I am using a UIToolbar in iOS and am trying to get a new button to 'arrive' by sliding in from the right. Is there a way to directly access the 'position' of the button on the bar? I currently have a messy workaround that is getting close to the desired effect, but i was hoping there was a way to move them using Core Animation, so i could implement the 'EaseInEaseOut' type timing functions. Any ideas?
- (void) testPart1 {
[NSTimer scheduledTimerWithTimeInterval:(0) target:self selector:#selector(testPart2:) userInfo:[NSNumber numberWithInt:500] repeats:NO];
}
- (void) testPart2:(NSTimer*)sender {
int countdown = [sender.userInfo integerValue];
theSpace.width = 10+(int)countdown;
itemTestButton.width = 49;
itemTestButton.width = 50;
countdown -= 5;
if(countdown>0)
[NSTimer scheduledTimerWithTimeInterval:(0.004) target:self selector:#selector(testPart2:) userInfo:[NSNumber numberWithInt:countdown] repeats:NO];
}
The premise here was using an NSTimer to change the width of a Fixed Space Bar Button item, and count down to zero. I found I had to change the width of an actual button to make it work, otherwise no 'animation' would occur. It's messy I know, someone must have a cleaner way.
I would suggest adding a plain UIView as a subview of the UIToolbar that is rendered exactly as the bar button would be (you could get this by calling renderInContext: on an existing button) and then animate that view into the proper position. In the completion block of that animation you could then set the real button and removeFromSuperview the animation view, and it will look indistinguishable to the user.
I want to show a status bar in the bottom of the iPhone like the one in Gmail account that is appear to indicate that it is checking mail. I have tried the following solution in this thread
Adding view on StatusBar in iPhone
but the status bar didn't appear, then i used the same code without any modification to show it in the top of the default status bar and it also didn't appear.
i have tried also another solution using MTStatusBarOverlay, when i tried to change its frame to be at the bottom i got a black rectangl in the middle of the screen
any help?
here is the code
// new class i have created
#interface BottomStatusBarOverlay : UIWindow
#end
#implementation BottomStatusBarOverlay
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Place the window on the correct level and position
self.windowLevel = UIWindowLevelStatusBar+1.0f;
self.frame = [[UIApplication sharedApplication] statusBarFrame];
self.alpha = 1;
self.hidden = NO;
// Create an image view with an image to make it look like a status bar.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
backgroundImageView.image = [[UIImage imageNamed:#"statusBarBackgroundGrey.png"] stretchableImageWithLeftCapWidth:2.0f topCapHeight:0.0f];
[self addSubview:backgroundImageView];
}
return self;
}
#end
// usage in my view controller in a button action
#implementation MainViewController
-(IBAction)showBottomStatusbar:(id)sender {
BottomStatusBarOverlay *bottomStatusBarOverlay = [[BottomStatusBarOverlay alloc] init];
bottomStatusBarOverlay.hidden = NO;
}
The code you posted shows that your showBottomStatusbar method creates a BottomStatusBarOverlay instance, but you never actually add it as a subview to anything.
I don't use the Gmail app on iPhone. So, I'm not sure what it looks like or how it functions. However, I have create a notification bar in the past that seems similar to what you described. It animates on to the bottom of the screen, shows a message for three seconds, and then slides back off. I accomplished this by adding the bar to the application's window, which will ensure it overlays any view the application is currently showing. You could, however, add the bar to any view that is currently active, if you don't need a global bar within your app. Here's how you get the app's window reference:
UIApplication* app = [UIApplication sharedApplication];
UIWindow* appWin = app.delegate.window;
To animate, you can use animateWithDuration, like so:
[UIView animateWithDuration:0.3
animations:^ {
// However you want to animate on to the screen.
// This will slide it up from the bottom, assuming the
// view's start position was below the screen.
view.frame = CGRectMake(0,
winHeight - viewHeight,
winWidth,
viewHeight);
}
completion:^(BOOL finished) {
// Schedule a timer to call a dismiss method after
// a set period of time, which would probably perform
// an animation off the screen.
dismissTimer = [NSTimer
scheduledTimerWithTimeInterval:3
target:globalMessage
selector:#selector(dismiss)
userInfo:nil
repeats:NO];
}];
Hope this helps.
I have a simple iPhone application that loads very quickly, so the splash screen only displays for a fraction of a second. Is there any way to control how long the splash screen displays? I have searched around, and have not found anything that seems like it would work. Do I have to create a subview with my splash image? How would I control its display time and switch between the subview and the mainview?
While I agree with the views expressed here and in the other question about why you should not "abuse" the default screen, it seems to me quite trivial to achieve this effect:
When starting up, simply put up a view that looks exactly like the splash screen and use an NSTimer to dismiss it. Really quite easy.
// viewDidLoad
[self performSelector:#selector(dismiss)
withObject:nil
afterDelay:yourTimeIntervalInSectons];
// dismiss
[self performSegueWithIdentifier:#"ID" sender:nil];
However, don't have the splash screen come on each time the application becomes active. I once did this for a very specific and useful purpose in the context of my app - but Apple rejected it. Hey, they even called me on Saturday evening to explain it to me.
While I agree with all that's been told here, I had to implement a splash screen with a timer once as well, so here's the code:
- (void)showSplashWithDuration:(CGFloat)duration
{
// add splash screen subview ...
UIImage *image = [UIImage imageNamed:#"Default.png"];
UIImageView *splash = [[UIImageView alloc] initWithImage:image];
splash.frame = self.window.bounds;
splash.autoresizingMask = UIViewAutoresizingNone;
[self.window addSubview:splash];
// block thread, so splash will be displayed for duration ...
CGFloat fade_duration = (duration >= 0.5f) ? 0.5f : 0.0f;
[NSThread sleepForTimeInterval:duration - fade_duration];
// animate fade out and remove splash from superview ...
[UIView animateWithDuration:fade_duration animations:^ {
splash.alpha = 0.0f;
} completion:^ (BOOL finished) {
[splash removeFromSuperview];
}];
}
Just call the function somewhere in your AppDelegate's -applicationDidFinishLaunching:withOptions: method
#asgeo1: code works just fine for me (I've used similar code in several projects). I've added an example project on my Dropbox for your convenience.
Don't do this and/or read why here
iOS Duration of Splash Screen (Default.png)
It does really make no sense to extend the duration of the Default.png.
Now, I completely agree with the above posts that you shouldn't do this, but if you still wish to it can be achieved very easily by adding the following to your AppDelegate.m.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
sleep(2);
}
The "2" represents how many seconds to sleep for. It will accept values like ".5"
I have a tabbarview application that has a button in one of the tabs. When Pressing that button, something will happen, and the user will be switched to another tab.
I made an animation in that button:
UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:0] view];
[UIView transitionFromView:fromView
toView:toView
duration:0.6
options:(UIViewAnimationOptionTransitionCurlDown)
completion:^(BOOL finished) {
if (finished) {
self.tabBarController.selectedIndex = 0;
}
}];
Which I got from here. However the problem is that after animating, I seem to have a gap on the top of the screen that is about as high as the status bar. Does anyone know what's causing this? This gap quickly closes when the animation finishes (which is when we do self.tabBarController.selectedIndex = 0
By the way, the problem still persist if I swap the animation to something else or even without animation.
Additional info, here's the frame details:
from frame: x:0.000000, y:0.000000, w:320.000000, h:411.000000
to frame: x:0.000000, y:0.000000, w:320.000000, h:431.000000
The tab bar controller's area also covers the area underneath the status bar. So it's own client view has origin.y of 20.
Thus you need to set the incoming view frame correctly before invoking the transition.
I've found a very hacky way to do it:
CGRect to = fromView.superview.frame;
to.origin.y -= 20;
fromView.superview.frame = to;
Anyone that can explain to me why I had to do this and a more elegant way to do this will get the answer accepted.