How to appear/ disappear UITableview in ios - ios

I am working video player.. I am using MPMediaplayer framework…
In video player below i am displaying one UIView, in this view i am displaying current video details like Video name and video description and video starting time and ending time… Those are details are displayed in UITableview.
The tableview adding to this uiview..Those are all things are done.
The uiview beside i put one button.. if i click the button then automatically appear uiview. if i click again the uiview disappear..this is also done.
now i am integrating animation for uiview like fade out(means if i click button appear uiview, after 10 seconds automatically disappear the uiview… )..that is my main requirement.. This is also done..
But problem is for example user scroll the uiview (video player details in tableview to scroll the tableview up and down) after 10 seconds automatically disappear. if user scroll the video player details i don’t want to disappear my tableview… but my problem if user scroll the video player details it is automatically disappear after 10 seconds..
so plz help me any body..How to handle this thing…My requirement is if user scroll the video player details i don’t want to disappear my tableview…
- (IBAction)InfoVisibleAction:(id)sender
{
if(UIView.hidden==NO)
{
UIView.hidden=YES;
ScheduleImageView.hidden=YES;
tableView.hidden=YES;
timeLabel1.hidden=YES;
}
else
{
UIView.hidden=NO;
ScheduleImageView.hidden=NO;
tableView.hidden=NO;
timeLabel1.hidden=NO;
[self performSelector:#selector(infoHiddenAction:) withObject:nil afterDelay:10];
}
}
- (IBAction)infoHiddenAction:(id)sender
{
if(UIView.hidden==NO)
{
UIView.hidden=YES;
ScheduleImageView.hidden=YES;
tableView.hidden=YES;
timeLabel1.hidden=YES;
}
}
- (IBAction)infoHiddenAction:(id)sender
{
if(UIView.hidden==NO)
{
SupportedView.hidden=YES;
ScheduleImageView.hidden=YES;
tableView.hidden=YES;
timeLabel1.hidden=YES;
}
}
-(void)viewDidLoad
{
tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 550, 130)];
tableView.delegate=self;
tableView.dataSource=self;
tableView.backgroundColor=[UIColor clearColor];
tableView.scrollEnabled=YES;
tableView.separatorColor=[UIColor clearColor];
[UIView addSubview:tableView];
}

The following should help
In Your class:
#implementation <YourClass> {
NSTimer* hideTimer;
}
Inside (IBAction)InfoVisibleAction:(id)sender
Instead of
[self performSelector:#selector(infoHiddenAction:) withObject:nil afterDelay:10];
Use
[hideTimer invalidate], hideTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(infoHiddenAction:) userInfo:nil repeats:NO];
Implement scrollViewDidScroll
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[hideTimer invalidate], hideTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:#selector(infoHiddenAction:) userInfo:nil repeats:NO];
}
Inside (IBAction)infoHiddenAction:(id)sender
Add
[hideTimer invalidate];

Related

How to change color of a UIButton while pressed ONLY and cancel color change if released before x amount of seconds?

I'm trying to make a button change color while being pressed for 3 seconds. Once timer reaches 3rd second the color change is permanent but if user releases button before time is up the button goes back to its original color. What I have so far is this:
in viewDidLoad
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(fireSomeMethod)];
longPress.minimumPressDuration = 3.0;
[self.view addGestureRecognizer:longPress];
in fireSomeMethod I have
- (void)someMethod {
[UIView transitionWithView:self.button
duration:2.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.button.backgroundColor = [UIColor redColor];
}
completion:^(BOOL finished) {
NSLog(#"animation finished");
}];
}
This requires me to hold the button down for 3 seconds for the animation to fire and animation itself takes 2 seconds to complete. The desired behavior is that animation starts when longPress starts and I release button before 3 seconds everything goes back to the way it was. Thanks for your help in advance
Make use of button event no need to use UILongPressGestureRecognizer
Make 2 action for your button, one is for Touch Down and other is for Touch Up Inside
like this
// For `Touch Up Inside`
- (IBAction)btnReleased:(id)sender {
[timer invalidate];
NSLog(#"time - %d",timeStarted);
}
// For `Touch Down`
- (IBAction)btnTouchedDown:(id)sender {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:#selector(_timerFired:)
userInfo:nil
repeats:YES];
timeStarted = 0;
}
- (void)_timerFired:(NSTimer *)timer {\
timeStarted++;
}
Create 2 variable timer of type NSTimer and timeStarted of type int. Fire the timer on Touch Down and invalidate it on Touch Up Inside, and in Touch Up Inside action method get the total time till your button is hold.As shown in the above code

Simple move uiimageview code not animating

I have the following routine to simply animate an image across the screen.
-(void)animateGrasland {
[UIView animateWithDuration:5 delay:0.0 options:UIViewAnimationOptionCurveLinear
animations:^{
CGRect newFrame = CGRectMake(100,100,1024,768);
self.grasland.frame = newFrame;
}
completion:^(BOOL finished) {
}
];
}
I want to start the animation immediately after I load the View. And to last for 5 seconds. So I have been experimenting with several options to calls of the function.
Option I - This option immediately shows the image at the new position, no animation!
- (void)viewDidLoad {
[super viewDidLoad];
[self animateGrasland];
}
Option II - This option animates the image to the new position. Bingo.
- (void)viewDidLoad {
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:#selector(animateGrasland) userInfo:nil repeats:NO];
}
I have bene playing with the delay in the Time a little and for 0.001 sec the animation will start. If the duration is 0.0001 sec the image is displayed immediately at the new position, so without animation. I expect that the duration of the parsing of the viewDidLoad (and other background routines causes this).
So because the initial position (0,0), which is set in the storyboard, is updated during the viewDidLoad, the Animation is not triggered. And the animation moves immediately to its finished state.
Try calling animateGrasland in viewDidAppear: instead of viewDidLoad, like this:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]
[self animateGrasland];
}
// Remove your implementation of the viewDidLoad method or at least the call to animateGrasland
viewDidLoad is called after the view is loaded into the memory, while viewDidAppear: is called after the view is added to the view hierarchy. In your case, this means right after the view is visible. Since you want your animation to start as soon as the view is visible, you should start it in viewDidAppear:

Initialize UISegmentedControl storyboard index

EDIT
Maybe I have described the problem incorrectly. Let me add that this segmented controller is controlling the speed of a NSTimer with the following code.
- (IBAction) segmentAction:(id)sender
{
speed = [[speeds objectAtIndex:[sender selectedSegmentIndex]] integerValue];
}
- (IBAction)startPause: (UIButton *)sender{
NSString *buttonTitle = sender.currentTitle;
if ([buttonTitle isEqualToString: #"Pause"]) {
[self.myButton setTitle:#"Resume" forState:UIControlStateNormal];
[timer invalidate];
}
else
{
[self.myButton setTitle:#"Pause" forState:UIControlStateNormal];
if ([self.deal length]>cardNum) {
timer = [NSTimer scheduledTimerWithTimeInterval:speed
target:self
selector:#selector(dealCard)
userInfo:nil
repeats:YES];
}
else
{
[timer invalidate];
}
}
}
When the user taps any of the segments in the segmentedController BEFORE tapping the startPause button, the NSTimer works fine. Nut if the user taps the startPause button before tapping a segment, no (desired) delays occur from the NSTimer. Does this help explain the situation any better?
EDIT
I have a UISegmentedControl in Storyboard and want to initialize it. It would be especially nice to initialize it in the Storyboard itself. The image below shows how the Med segment is selected, but when the app starts, Med is NOT selected; rather the user has to trigger a Value changed event. How do I get it selected, initially? One of the other questions here on SO suggested the following code, but I have not figured out how to associate the UISegmentedControl in my Storyboard with the name segmentControl.
segmentControl.selectedSegmentIndex=-1;

iOS - display a view for few seconds and change view

I'm designing a app where it first shows a terms and conditions view and then on accepting it, it moves on to next view where I've used a UIImage to add a background image, so that I could display a welcome image for my app and then after 5 seconds I have changed the view to user login. I've used the view based application template without storyboards and I've also enabled ARC.
I've used the following codes:
Accepting Terms and Condition [accept.h, accept.m, accept.xib]:
- (IBAction)AcceptPractTandC:(id)sender
{
PractionerImage *PracImage = [[PractionerImage alloc] init];
[self presentViewController:PracImage animated:YES completion:nil];
}
Displaying Image for 5 Seconds and showing next view [PractionerImage.h, PractionerImage.m, PractionerImage.xib]:
- (void)viewDidLoad
{
[super viewDidLoad];
count = 0;
PracImage = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:#selector(PracImageSkip) userInfo:nil repeats:YES];
}
- (void)PracImageSkip
{
count += 1;
if (count > 5) {
ViewController *Intro = [[ViewController alloc]init];
[self presentViewController:Intro animated:YES completion:nil];
}
}
and I have the user details in the files ViewController.m, ViewController.h, ViewController.xib.

Show/hide a button after a period of time

I am currently making an app that has a complex loading screen. I have created the loader using UI Animation, but want to add a button that will appear once the loading bar has finished. I have come across the idea of hiding the button for a certain period of time, or making it appear after a certain period of time.
How would I show/hide the button after a period of time?
You could invoke your method to show the button after a certain period of time:
[self performSelector:#selector(showButton) withObject:nil afterDelay:0.5];
Or, probably better, if you want to animate the appearance of the button, you can do both the animation and the delay in a single call, e.g. assuming the button originally has alpha of 0.0:
[UIView animateWithDuration:0.25
delay:0.5
options:nil
animations:^{
myButton.alpha = 1.0;
}
completion:^(BOOL finished){
// if you want to do anything when animation is done, do it here
}
];
Using NSTimer should be the easiest way.
Create NSTimer to do that,
Timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:#selector(hideButton:) userInfo:nil repeats:NO];
-(void)hideButton:(UIButton *)hideButton {
if hideButton.isHidden == false {
hideButton.hidden=TRUE;
} else {
hideButton.hidden = FALSE
}

Resources