ios animation one by one - ios

I have some views and I want to display them one by one . I can't find how to do this . Instead , if I use the following code , all the views appear at once .
NSTimer *timer1 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(showStar2) userInfo:nil repeats:NO];
NSTimer *timer2 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(showStar3) userInfo:nil repeats:NO];
NSTimer *timer3 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(showStar4) userInfo:nil repeats:NO];
NSTimer *timer4 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(showStar5) userInfo:nil repeats:NO];
[timer1 fire];
[timer2 fire];
[timer3 fire];
[timer4 fire];
-(void)showStar2
{
[UIView beginAnimations:#"anim1" context:NULL];
[UIView setAnimationDuration:0.5];
[stars[1] setAlpha:1];
[UIView commitAnimations];
}
All the showStar functions are identical except the lines
[UIView beginAnimations:#"anim1" context:NULL];
[stars[1] setAlpha:1];
which have different arguments . stars is an array of UIImageView's.
Any suggestion is welcome .

Actually you are firing all the timers exactly after 2 seconds. Change the timeInterval for different timers.
Instead you can use a single NSTimer that will fire repeatedly.
Declare NSUInteger count; in .h file.
Start a NSTimer as follows:
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(showStar:) userInfo:nil repeats:YES];
And your showStar method should be as follows:
-(void)showStar:(NSTimer*)timer
{
if( count > 0 )
{
[stars[count-1] setAlpha:0];
}
[UIView beginAnimations:#"anim1" context:NULL];
[UIView setAnimationDuration:0.5];
[stars[count] setAlpha:1];
[UIView commitAnimations];
count++;
if( count == 4 )
{
[timer invalidate];
count = 0;
}
}
The following code has been added.
if( count > 0 )
{
[stars[count-1] setAlpha:0];
}

All your timers are using the same time delay, so that's what the all appear at once. Also, don't call fire on the timers, they fire automatically. Calling fire probably makes them fire right away.
Incidentally, you don't need to use timers to trigger the animations, you can just add this to your animations:
[UIView setAnimationDelay:x];
And use a different x for each view.

I would do something like this
- (void)firstAnimation{
[UIView animateWithDuration:2.0f animations:^{
//first animation
} completion:^(BOOL finished){
[self secondAnimation];
}];
}
probably with recursion and a flag for current animation would be cleaner though

In my opinion your implementation is wrong.
Better to place a UImageView on your UIView.
Next create an NSArray of images and load then onto the imageView.
arrAnimations = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"image1.png],.....nil];
then call
imageView.animationImages= arrAnimations;
imageView.animationDuration=2;
[imageView startAnimating];

Related

Cant make UIlabel text blink in Xcode

I have been trying to make my UILabel blink in Xcode
but the problem is it does not blink
Here is my code:
self.labelCountdownTime.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:FLT_MAX];
self.labelCountdownTime.alpha = 1.0;
[UIView commitAnimations];
Is there something I'm doing wrong.
Thanks
You can use NSTimer to blink your text in UILabel like so:
NSTimer *timer = [NSTimer
scheduledTimerWithTimeInterval:(NSTimeInterval)(1.0)
target:self
selector:#selector(blink)
userInfo:nil
repeats:YES];
BOOL blinkStatus = NO;
And the selector will call this function:
-(void)blink{
if(blinkStatus == NO){
yourLabel.alpha = 1.0;
blinkStatus = YES;
}else {
yourLabel.alpha = 0.0;
blinkStatus = NO;
}
}
Or you can use method animationWithDuration of UIView like so:
self.yourLabel.alpha = 0;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
self.yourLabel.alpha = 1;
} completion:nil];
Hope this will help you.
I Think you are wanting some thing more like the following:
Create a timer in your controller:
#property (strong, nonatomic) NSTimer *timer;
then start the timer where you need it to start, like maybe in viewDidLoad
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(toggleLabelAlpha) userInfo:nil repeats:YES];
and here is the selector:
- (void)toggleLabelAlpha {
[self.labelCountdownTime setHidden:(!self.labelCountdownTime.hidden)];
}
Try this ?

Xcode Disposing memory - images taking up too much memory and won't deallocate

Updated:
I have a lot of view controllers and the app is image heavy. Each is presented modally at the moment. I'm disposing of all my images,timers etc and whatever else in viewwilldisappear on every view controller, but when it segues it just seems to be allocating memory continually on top of the previous VC and everything else without getting rid of a single thing which eventually crashes it (i know this will happen with modal segues).
How can i change this? I have tried embedding my controllers in a navigation controller but the same problem is still happening where it will not release any of the images on the controllers. Here is an example of my code and where i'm getting rid of what i've created in VWD. VWD is definitely being called. Hopefully this makes sense to someone, thanks in advance.
#interface AnimationStartViewController ()
#end
#implementation AnimationStartViewController
SystemSoundID skipintro;
-(void) viewDidLoad
{
[super viewDidLoad];
(sleep(2.5));
NSString *music=[[NSBundle mainBundle]pathForResource:#"1Animation" ofType:#"mp3"];
animationaudio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:music] error:NULL];
animationaudio.delegate= (id)self;
animationaudio.numberOfLoops=-1;
[animationaudio play];
NSURL *skipintroURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Click" ofType:#"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)skipintroURL, &skipintro);
//Text Timers
text1timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text1show:) userInfo:nil repeats:NO];
text2timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text2show:) userInfo:nil repeats:NO];
text3timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text3show:) userInfo:nil repeats:NO];
text4timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text4show:) userInfo:nil repeats:NO];
text5timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text5show:) userInfo:nil repeats:NO];
text6timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text6show:) userInfo:nil repeats:NO];
text7timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text7show:) userInfo:nil repeats:NO];
text8timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text8show:) userInfo:nil repeats:NO];
logotimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(showlogo) userInfo:nil repeats:NO];
pushtimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:#selector(performthesegue) userInfo:nil repeats:NO];
//Text Timers invalidate
stoptext1timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext1) userInfo:nil repeats:NO];
stoptext2timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext2) userInfo:nil repeats:NO];
stoptext3timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext3) userInfo:nil repeats:NO];
stoptext4timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext4) userInfo:nil repeats:NO];
stoptext5timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext5) userInfo:nil repeats:NO];
stoptext6timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext6) userInfo:nil repeats:NO];
stoptext7timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext7) userInfo:nil repeats:NO];
stoptext8timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext8) userInfo:nil repeats:NO];
moveAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(moveAnimation) userInfo:nil repeats:YES];
stopAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:#selector(StopAnimation) userInfo:nil repeats:NO];
}
//scrolling Animation.
- (void) moveAnimation {
animation.center = CGPointMake(animation.center.x, animation.center.y -2);
}
//Stop
- (void) StopAnimation {
[moveAnimationTimer invalidate];
moveAnimationTimer = nil;
}
//====================== Text animations
//AttheGateof
-(void)Text1show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:0.70
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
Atthegateof.alpha = 1.0f;
}
completion:^(BOOL finished) {
Atthegateof.alpha = 1.0f;
}];
}
//MidnightZoo
-(void)Text2show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:1.75
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
MidnightZoo.alpha = 1.0f;
}
completion:^(BOOL finished) {
MidnightZoo.alpha = 1.0f;
}];
}
//Who lives inside
-(void)Text3show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:2.9
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Wholivesinside.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
// Thedeepblackblue
-(void)Text4show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:3.3
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Thedeepblackblue.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//unlockthegate
-(void)Text5show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:7
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Unlockthegate.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//tocomeinside
-(void)Text6show:(NSTimer *)timer {
//music 'high' point
[UIView animateWithDuration:2 delay:7.5
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Tocomeinside.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//behindeachlock
-(void)Text7show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:8.2
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Behindeachlock.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//something hides
-(void)Text8show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:8.7
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Somethinghides.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//======================================= Get rid of text
//indvalidate 1
-(void)invalidatetext1 {
[stoptext1timer invalidate];
stoptext1timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Atthegateof.alpha = 0;
} completion:^(BOOL finished) {
[Atthegateof removeFromSuperview];
} ];
}
//invalidate 2
-(void)invalidatetext2 {
[stoptext2timer invalidate];
stoptext2timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
MidnightZoo.alpha = 0;
} completion:^(BOOL finished) {
[MidnightZoo removeFromSuperview];
} ];
}
//invalidate 3
-(void)invalidatetext3 {
[stoptext3timer invalidate];
stoptext3timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Wholivesinside.alpha = 0;
} completion:^(BOOL finished) {
[Wholivesinside removeFromSuperview];
} ];
}
//invalidate 4
-(void)invalidatetext4 {
[stoptext4timer invalidate];
stoptext4timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Thedeepblackblue.alpha = 0;
} completion:^(BOOL finished) {
[Thedeepblackblue removeFromSuperview];
} ];
}
//invalidate 5
-(void)invalidatetext5 {
[stoptext5timer invalidate];
stoptext5timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Unlockthegate.alpha = 0;
} completion:^(BOOL finished) {
[Unlockthegate removeFromSuperview];
} ];
}
//invalidate 6
-(void)invalidatetext6 {
[stoptext6timer invalidate];
stoptext6timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Tocomeinside.alpha = 0;
} completion:^(BOOL finished) {
[Tocomeinside removeFromSuperview];
} ];
}
//invalidate 7
-(void)invalidatetext7 {
[stoptext7timer invalidate];
stoptext7timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Behindeachlock.alpha = 0;
} completion:^(BOOL finished) {
[Behindeachlock removeFromSuperview];
} ];
}
//invalidate 8
-(void)invalidatetext8 {
[stoptext8timer invalidate];
stoptext8timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Somethinghides.alpha = 0;
} completion:^(BOOL finished) {
[Somethinghides removeFromSuperview];
} ];
}
//=======================================
-(void)showlogo {
[UIView animateWithDuration:2.0 delay:16.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
zoowhologo.alpha = 1.0f;
}
completion:^(BOOL finished) {
zoowhologo.alpha = 1.0f;
}];
}
-(void)performthesegue {
[self performSegueWithIdentifier:#"pushgototitle" sender:nil];
}
- (void)didReceiveMemoryWarning
{
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSLog(#"viewilldisappear was called");
[animationaudio stop];
[text1timer invalidate], text1timer=nil;
[text2timer invalidate], text2timer=nil;
[text3timer invalidate], text3timer=nil;
[text4timer invalidate], text4timer=nil;
[text5timer invalidate], text5timer=nil;
[text6timer invalidate], text6timer=nil;
[text7timer invalidate], text7timer=nil;
[text8timer invalidate], text8timer=nil;
[stoptext1timer invalidate], stoptext1timer=nil;
[stoptext2timer invalidate], stoptext2timer=nil;
[stoptext3timer invalidate], stoptext3timer=nil;
[stoptext4timer invalidate], stoptext4timer=nil;
[stoptext5timer invalidate], stoptext5timer=nil;
[stoptext6timer invalidate], stoptext6timer=nil;
[stoptext7timer invalidate], stoptext7timer=nil;
[stoptext8timer invalidate], stoptext8timer=nil;
[logotimer invalidate], logotimer=nil;
[pushtimer invalidate], pushtimer=nil;
[moveAnimationTimer invalidate], moveAnimationTimer=nil,
[stopAnimationTimer invalidate], stopAnimationTimer=nil;
AudioServicesDisposeSystemSoundID(skipintro);
[Atthegateof removeFromSuperview], Atthegateof=nil;
[MidnightZoo removeFromSuperview], MidnightZoo=nil;
[Wholivesinside removeFromSuperview], Wholivesinside=nil;
[Thedeepblackblue removeFromSuperview], Thedeepblackblue=nil;
[Unlockthegate removeFromSuperview], Unlockthegate=nil;
[Tocomeinside removeFromSuperview], Tocomeinside=nil;
[Behindeachlock removeFromSuperview], Behindeachlock=nil;
[Somethinghides removeFromSuperview], Somethinghides=nil;
[topper removeFromSuperview], topper=nil;
[skip removeFromSuperview], skip=nil;
[zoowhologo removeFromSuperview], zoowhologo=nil;
[animation removeFromSuperview], animation = nil;
[stopanimation removeFromSuperview], stopanimation = nil;
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)skipintro:(id)sender {
AudioServicesPlaySystemSound(skipintro);
[animationaudio stop];
[pushtimer invalidate];
[self performSegueWithIdentifier:#"pushgototitle2" sender:self];
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
}
Several things.
If you present view controllers modally, they get stacked up one on top of the next, and none of them get released until you dismiss them. Make sure you're not creating a new instance of a previous view controller and pushing it modally instead of dismissing back to the desired VC.
Second,
It used to be that when a view controller was moved off-screen, it's view hierarchy was unloaded, freeing up most of the memory it took. That's no longer true. (and hasn't been for quite a few major iOS releases. I want to say this changed in iOS 4, but am not positive of this.)
If a view controller is in memory, so is it's entire view hierarchy, including any images that are installed in image views inside those views.
You can indeed implement a viewWillDisappear method and use that method to nil out any data structures that are not installed in your view hierarchy. You then need to implement a viewWillAppear method that reloads those data structures.
If your app presents a series of view controllers modally, and then the user "unrolls" each view controller and returns back to the root view controller then your method of using modal presentation is reasonable. (Using a navigation controller and a stack of pushed view controllers might be better, but you claim not.) Both approaches keep a stack of all the previously visited view controllers active and in memory.
If instead your UX has your user move from VC to VC without the need to return, you should instead implement your own custom segue that dismisses the previous view controller, or perhaps uses a child view controller that it swaps for another one as the user navigates.

A UIScrollview that auto scroll and Stop at every Pages for atleast 2seconds

I am using NSTimer to move through my UIScrollview, but I can't get to make it stop at every page for like let's say a second or two so users can be able to preview and click if they want to or when they are scrolling around the images in the UIScrollview my Code is below....:
-(void) onTimer {
CGPoint rightOffset = CGPointMake(responseScroll.contentSize.width - responseScroll.bounds.size.width, 0);
[responseScroll setContentOffset:rightOffset animated:YES];
}
-(void)viewDidLoad {
/-------/
[NSTimer scheduledTimerWithTimeInterval:0.008 target:self selector:#selector(onTimer) userInfo:nil repeats:YES];
}
Make the timer interval 2.0:
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(onTimer) userInfo:nil repeats:YES];
This means that the timer will fire every 2 seconds.
If you want to shift one page over, you need to adjust your onTimer method:
CGPoint rightOffset = CGPointMake(responseScroll.contentOffset.x + responseScroll.frame.size.width, 0);
[responseScroll setContentOffset:rightOffset animated:YES];
Consider using UIAnimations instead
-(void)viewDidLoad{
[self moveScrollView];
}
-(void)moveScrollView{
CGPoint rightOffset = CGPointMake(responseScroll.contentOffset.x+responseScroll.bounds.size.width, 0);
if(rightOffset.x+responseScroll.bounds.size.width<=responseScroll.contentSize.width){
[UIView animateWithDuration:1 animations:^{
[responseScroll setContentOffset:rightOffset animated:NO];
} completion:^(BOOL finished) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self moveScrollView];
});
}];
}
}
Here is my answer, this is in swift. This will scroll the pages in scrollview infinitely.
private func startBannerSlideShow()
{
UIView.animate(withDuration: 6, delay: 0.1, options: .allowUserInteraction, animations: {
scrollviewOutlt.contentOffset.x = (scrollviewOutlt.contentOffset.x == scrollviewOutlt.bounds.width*2) ? 0 : scrollviewOutlt.contentOffset.x+scrollviewOutlt.bounds.width
}, completion: { (status) in
self.startBannerSlideShow()
})
}

NSTimer not invalidating in iOS 7, when navigation to new view in iPhone [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am facing some issue related to NSTimer. I need to show a UIButton at the bottom in timeframe of 5 seconds. I implemented NSTimer functionality and it showing button in that time. However when i navigate to a new View. I need to stop that NSTimer or invalidate. I have done that in - (void)viewDidDisappear:(BOOL)animated. However NSTimer is still being executed. Its not been stopped at any time.Below is my code.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self._sizeNowButton = [[UIButton alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height+70, 320, 44)];
[TLStylesheet useTurquoiseStyleForButton:self._sizeNowButton withText:NSLocalizedString(#"Size Now", nil) withFontSize:BUTTON_BOTTOM_FONT_SIZE];
[self._sizeNowButton addTarget:self action:#selector(sizeNowClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self._sizeNowButton];
SEL tSelector = NSSelectorFromString(#"aTimer");
self._aTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:tSelector userInfo:nil repeats:NO];
}
-(void)aTimer
{
self._tTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(showButton) userInfo:nil repeats:YES];
}
-(void)showButton {
if([self._sizeNowButton isHidden] )
{
self._sizeNowButton.hidden = NO;
CGRect newFrame = CGRectMake(self._sizeNowButton .frame.origin.x , self._sizeNowButton .frame.origin.y - 44, self._sizeNowButton .frame.size.width, self._sizeNowButton .frame.size.height);
[UIView animateWithDuration:0.5f
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[self._sizeNowButton setFrame:newFrame];
}
completion:nil];
}
else
{
CGRect newFrame = CGRectMake(0, self.view.frame.size.height, 320, 44);
[UIView animateWithDuration:0.5f
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
[self._sizeNowButton setFrame:newFrame];
}
completion:nil];
self._sizeNowButton .hidden = YES;
}
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self._tTimer invalidate];
self._tTimer = nil;
self._sizeNowButton = nil;
}
You are instantiating self._aTimer but invalidating self._tTimer.
As you appear to trigger two different timers (_aTimer and _tTimer), you will want to disable both in your viewWillDisappear:.
if (self._aTimer)
[self._aTimer invalidate];
self._aTimer = nil;
if (self._tTimer)
[self._tTimer invalidate];
self._tTimer = nil;
try this:
start timer like this
self. _tTimer = [NSTimer timerWithTimeInterval:5.0 target:self selector:#selector(showButton) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self. _tTimer forMode:NSDefaultRunLoopMode];
[self. _tTimer fire];
and stop like this-
if (self. _tTimer)
{
[self. _tTimer invalidate];
self. _tTimer = nil;
}

Bounce UIScrollView - hint that there's more

I'm developing an app with a scroll view in it. It's not immediately obvious that there's more content, and there's no scroll indicator (scroll view is paged).
So, to give the user a 'hey, there's something down here...', I would like to have the scroll view do a subtle bounce - down then up - on launch. I've tried this:
- (void)viewDidLoad
....
[NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:#selector(bounceScrollView) userInfo:nil repeats:NO];
}
- (void)bounceScrollView
{
[self.verticalScrollViews[0] scrollRectToVisible:CGRectMake(0, 600, 1, 1) animated:YES];
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:#selector(_unbounceScrollView) userInfo:nil repeats:NO];
}
- (void)_unbounceScrollView
{
[self.verticalScrollViews[0] scrollRectToVisible:CGRectZero animated:YES];
}
However, this code makes the view get 'stuck' at about halfway between two pages.
Any help?
Idea 1: You need to turn off paging, animate the bounce, and turn the paging back on.
Idea 2: Your second move is coming way too soon:
scheduledTimerWithTimeInterval:0.01
Experiment with longer time intervals! I would start with 0.4.
Idea 3: Instead of your bounce, why not use flashScrollIndicators? This is exactly what it is for!
I had a memory problems when using NSTimer. That's why I used another solution for scrollView preview.
[UIView animateWithDuration:1.0
delay:0.00
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_scrollView.contentOffset = CGPointMake(200,0);
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
delay:0.00
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_scrollView.contentOffset = CGPointMake(0,0);
}
completion:^(BOOL finished){
}
];
}
];

Resources