I need to popup actionsheet above tabbar in my present viewcontroller, but it should not overlap tabbar(i need to see tabbar clearly) - objective-c

I need to popup transperant actionsheet above tabbar in my present viewcontroller, but it should not overlap tabbar(i need to see tabbar clearly).

To create a transparant background on a UIActionsheet you have to set the delegate and then you can do:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
[actionSheet.layer setContents:nil];
}
To create a custom UIView that animates in from the bottom you can do>
bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 250)];
bottomView.backgroundColor = [UIColor redColor];
bottomView.hidden = YES;
[self.view addSubview:bottomView];
UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
testButton.frame = CGRectMake(20, 50, 280, 40);
testButton.backgroundColor = [UIColor greenColor];
[bottomView addSubview:testButton];
[self animateBottomViewIn];
And have the following methods:
-(void)animateBottomViewIn
{
bottomView.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
bottomView.frame = CGRectMake(0, self.view.frame.size.height - bottomView.frame.size.height, self.view.frame.size.width, bottomView.frame.size.height);
} completion:^(BOOL finished) { }];
}
-(void)animateBottomViewOut
{
[UIView animateWithDuration:0.3 animations:^{
bottomView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, bottomView.frame.size.height);
} completion:^(BOOL finished) {
bottomView.hidden = YES;
}];
}

Related

Using cgaffinetransformmakescale and cgaffinetransformmakerotation deforms my view

I have a simple UIView:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view.backgroundColor = [UIColor greenColor];
[self.view addSubview:view];
self.someView = view;
Then I do this
[UIView animateWithDuration:10
delay:1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.someView.center = CGPointMake(CGRectGetWidth(self.view.bounds) - CGRectGetWidth(self.someView.frame) / 2, 150);
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
self.someView.transform = CGAffineTransformScale(transform, 2, 0.5);
}
completion:^(BOOL finished) {
}];
While is executed this simple animation, someView is deformed. As far as I know it should rotate and change it's size. I can't understand why is it happening so, how can i fix it?
Thanks
The problem is animating a combined scaling and rotation. The end result is the same as animating them separately, but the frames in between are not easily defined. So the animation framework makes a guess, and it is not what you are expecting.
If you want the animation to show a rotation and scaling separately, you need to apply them separately to the view hierarchy. For example:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view.backgroundColor = [UIColor greenColor];
[self.view addSubview:view];
self.someView = view;
UIView *innerView = [[UIView alloc] initWithFrame:view.bounds];
innerView.backgroundColor = [UIColor blueColor];
[view addSubview:innerView];
self.someInnerView = innerView;
The animation splits the transform:
[UIView animateWithDuration:10
delay:1
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.someView.center = CGPointMake(CGRectGetWidth(self.view.bounds) - CGRectGetWidth(self.someView.frame) / 2, 150);
self.someView.transform = CGAffineTransformMakeRotation(M_PI);
self.someInnerView.transform = CGAffineTransformMakeScale(2, 0.5);
}
completion:^(BOOL finished) {
}];

How can I cover the entire iPhone screen with the keyboard being show?

Imagine a simple translucent mask that I'd like to cover the whole iphone screen:
UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
maskView.backgroundColor = [UIColor blackColor];
maskView.alpha = 0.0f;
maskView.userInteractionEnabled = NO;
[[[UIApplication sharedApplication] keyWindow] addSubview:maskView];
[UIView animateWithDuration:.7 delay:.5f options:UIViewAnimationCurveEaseOut
animations:^{
maskView.alpha = .3f;
}
completion:^(BOOL finished) {
}];
However, the screen is displaying the keyboard ( I have made a textfiled in the view a first responder).
How can I cover the keyboard with my maskView?

Rotate between 2 views

I have two views. How do I transition between them by rotation? I want to rotate the first view to get the second view... Thanks.
I tried using [UIView transitionFromView but it does not have a rotation parameter.
It might be what you are expecting. But, not quite as you expected since it is not using transition animation simply adding or removing the subviews.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(60, 140, 200, 200)];
view1.backgroundColor = [UIColor greenColor];
[self.view addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(60, 140, 200, 200)];
view2.backgroundColor = [UIColor redColor];
[self.view addSubview:view2];
view2.alpha = 0;
[UIView transitionWithView:view1 duration:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
view1.transform = CGAffineTransformMakeRotation(M_PI/2);
} completion:^(BOOL com){
view2.alpha = 1;
[view1 removeFromSuperview];
}];

UIButton not working on animated subView

I want to add two buttons to a subview that appears over the parent view when the view will appear. The buttons are initialized correctly and appear but they don´t react when pressed. Does anybody know why? Here is my code:
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor blackColor];
//Animation View
imageView= [[UIImageView alloc] initWithFrame:CGRectMake(0, 499, 320, 0)];
imageView.image = [UIImage imageNamed:#"trans.png"];
[imageView setClipsToBounds:YES];
[imageView setContentMode:UIViewContentModeBottom];
[self.view addSubview:imageView];
[UIView animateWithDuration:1.0f
delay:0.5f
options:UIViewAnimationOptionCurveEaseOut
animations:^(void) {
imageView.frame = CGRectMake(0, 92, 320, 320);
}
completion:NULL];
[self.view bringSubviewToFront:imageView];
// Animation View Buttons
//1 Amazon
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *button=[UIImage imageNamed:#"button.png"];
[button1 setImage:button forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 290, 80, 30);
button1.backgroundColor=[UIColor whiteColor];
button1.showsTouchWhenHighlighted=YES;
[button1 addTarget:self
action:#selector(openAmazon:)
forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:button1];
//2 iTunes
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setImage:button forState:UIControlStateNormal];
button2.frame = CGRectMake(82, 290, 80, 30);
button2.backgroundColor=[UIColor whiteColor];
button2.showsTouchWhenHighlighted=YES;
[button2 addTarget:self
action:#selector(openiTunes:)
forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:button2];
}
you need to use the option UIViewAnimationOptionAllowUserInteraction
...
options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
...
Make sure you set the userInteractionEnabled property on the imageView:
[imageView setUserInteractionEnabled:YES];
[self.view bringSubviewToFront:imageView];
you are bringing your image view to the front after increasing its frame, this is blocking the buttons actions

iOS – Animation glitch with UIToolbar

I'm getting a "weird" animation glitch when I add a UIToolbar to the view. I'm animating the UIToolbar so it slides up from the bottom together with either a UIPickerView or a UIDatePicker. At first I see it's sliding up but after the animation is finished it quickly disappears. This happens when I slide down (animating the UIPickerView to slide down off the screen) and right after that I have another UIPickerView slide up.
I noticed that if I set a delay (- performSelector...) on the slide up call for 0.3 seconds it will display the UIToolbar properly (anything less than 0.3 seconds will still have the same glitch). What might be causing this?
EDIT: Perhaps I should place both the UIToolbar and UIDatePicker in a new UIView container?
This is the code I'm using:
if ([self.view.subviews containsObject:self.dateRepeatPicker]) {
[self dismissDateRepeatPickerSegmentChanged:NO];
// "Hack", if I don't delay this call the UIToolbar will not display
[self performSelector:#selector(showDatePicker) withObject:nil afterDelay:0.3];
} else if (![self.view.subviews containsObject:self.datePicker]) {
[self showDatePicker];
}
- (void)dismissDateRepeatPickerSegmentChanged:(BOOL)segmentChanged {
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height, 320, 44);
CGRect dateRepeatPickerTargetFrame = CGRectMake(0, self.view.bounds.size.height+44, 320, 216);
[UIView animateWithDuration:0.2
animations:^{
self.pickerToolbar.frame = toolbarTargetFrame;
self.dateRepeatPicker.frame = dateRepeatPickerTargetFrame;
}
completion:^(BOOL finished) {
if (segmentChanged) {
[self.pickerToolbar removeFromSuperview];
[self.dateRepeatPicker removeFromSuperview];
[self.remindMeTableView reloadData];
} else {
[self.pickerToolbar removeFromSuperview];
[self.dateRepeatPicker removeFromSuperview];
}
}];
}
- (void)showDatePicker {
// Create the Toolbar over the Picker
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44);
if (self.pickerToolbar == nil) {
self.pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
self.pickerToolbar.barStyle = UIBarStyleBlack;
self.pickerToolbar.translucent = YES;
}
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"picker-dismiss.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(dismissDatePickerToolbar)];
[self.pickerToolbar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
[self.view addSubview:self.pickerToolbar];
// Create the Picker under the Toolbar
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216);
if (self.datePicker == nil) {
self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)];
[self.datePicker setMinuteInterval:5];
[self.datePicker addTarget:self action:#selector(changeDate:) forControlEvents:UIControlEventValueChanged];
}
[self.view addSubview:self.datePicker];
[UIView animateWithDuration:0.2 animations:^{
self.pickerToolbar.frame = toolbarTargetFrame;
self.datePicker.frame = datePickerTargetFrame;
}];
}
Solved by adding the UIPickerView and the UIToolbar to a containing UIView and then animating the containing UIView.