How to animate only the frame ie. the subview and not the entire view and how to add segmented control buttons inside that subview? I want the subview to popup when i click a button, but the subview should be translucent in such a way that the parent view behind is visible.
Asked
Active
Viewed 895 times
-3
-
What code have you tried? What problems are you running into? – zachjs Oct 10 '12 at 04:20
-
1I'm seeing about three separate questions here. – geraldWilliam Oct 10 '12 at 04:23
-
You can add UIView as subview on your mainView, and make it transparent. Also add close button to remove it from mainView. – Kamleshwar Oct 10 '12 at 04:26
-
Check the following links. This should resolve your issues. [SubView slide in animation, iphone][1] [how-do-you-create-a-transparent-background-for-a-uiview][2] [1]:http://stackoverflow.com/questions/7343915/subview-slide-in-animation-iphone [2]:http://stackoverflow.com/questions/6655093/how-do-you-create-a-transparent-background-for-a-uiview – iDev Oct 10 '12 at 04:30
3 Answers
1
First you make youe subview
transparent:
[subview setAlpha:0.5f];
And then add this code before the addSubView
line:
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionMoveIn]; // you can try carious options here
[animation setSubtype:kCATransitionFromRight]; // here too
[animation setDuration:0.3];
[animation setValue:@"Throb" forKey:@"MyAnimationType"];
[subview.layer addAnimation:animation forKey:nil];

Kanan Vora
- 2,124
- 1
- 16
- 26
1
Take UIView global if you want to add and remove this also add subview in your this view
UIView *tempView=[[UIView alloc]initWithFrame:sel.view.frame];
/////== Add your subviews in this tempView
tempView.transform = CGAffineTransformMakeScale(1.3, 1.3);
tempView.alpha = 0;
[UIView animateWithDuration:.35 animations:^{
tempView.alpha = 0.94;
tempView.transform = CGAffineTransformMakeScale(1, 1);
}];
tempView.frame=CGRectMake(0, 0, 320, 480);
[self.view addSubview:tempView];
Update :
First take object of UIView in your .h file like
UIView *tempView;
BOOL isOpen;
in viewWillDidLoad:
method just define this
isOpen = NO;
and after use this code
-(IBAction)btnSetting_Clicked:(id)sender
{
if (isOpen) {
isOpen = NO;
[tempView removeFromSuperview];
}
else {
isOpen = YES;
tempView=[[UIView alloc]initWithFrame:self.view.frame];
/////== Add your subviews in this tempView
[tempView addSubview:yourSegControl];
tempView.transform = CGAffineTransformMakeScale(1.3, 1.3);
tempView.alpha = 0;
[UIView animateWithDuration:.35 animations:^{
tempView.alpha = 0.94;
tempView.transform = CGAffineTransformMakeScale(1, 1);
}];
tempView.frame=CGRectMake(0, 0, 320, 480);
[self.view addSubview:tempView];
}
}
i hope this help you..
:)

Paras Joshi
- 20,427
- 11
- 57
- 70
-
It was very useful, thanks. But now i want to add the segmented control buttons inside the popup subview and i also want the pop up to disappear, when i click the settings button again. Can u give me the exact code for all these things? That includes both the interface and implementation part. – The X-Coder Oct 12 '12 at 11:52
-
just add the segment control in your PopUpView and set the bool value , when its open set as a yes like isOpen = YES; when again button clicked at that time set as a No like isOpen = NO; , if my answer is useful to you then accept answer or up-vote.. :) – Paras Joshi Oct 12 '12 at 12:01
0
You can Add subview to main View
CGRect frame = CGRectMake(x, y, width, height); // Replacing with your dimensions
UIView *subView = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:subView];
You can make it transparent using
[subView setAlpha:0.2];
You can add any UI Controls to this view.
Hope this will help you out.

Kamleshwar
- 2,967
- 1
- 25
- 27