I want to create a menu that appears sliding from a side of my view, so I programmatically created a UIView and a UITableView, but, when it appears I can't select the cells in my view, here's the code where I created the view and the table:
paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 400)];
[paintView setBackgroundColor:[UIColor clearColor]];
tablaConfig = [[UITableView alloc]initWithFrame:CGRectMake(-160, 0, 160, 400) style:UITableViewStylePlain];
tablaConfig.delegate = self;
tablaConfig.dataSource = self;
tablaConfig.userInteractionEnabled = YES;
tablaConfig.scrollEnabled = NO;
tablaConfig.backgroundColor = [UIColor lightGrayColor];
[paintView addSubview:tablaConfig];
And here's the code where I make the table appear and disappear:
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
if (self.view.frame.origin.x == 0) {
//[self.view addSubview:paintView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
// Move right.
rect.origin.x += 160;
rect.size.width -= 160;
self.view.frame = rect;
[UIView commitAnimations];
selector = false;
tablaConfig.userInteractionEnabled = YES;
}
}
else {
if (self.view.frame.origin.x == 160) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5]; // if you want to slide up the view
CGRect rect = self.view.frame;
rect.origin.x -= 160;
rect.size.width += 160;
self.view.frame = rect;
[UIView commitAnimations];
selector = true;
tablaConfig.userInteractionEnabled = NO;
}
//[paintView removeFromSuperview];
}
}
Hope you can help
EDIT:
When I use this, I can select the cells, but lose the sliding effect, how can I get both?
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
[self.view addSubview:tablaConfig];
selector = false;
}
else {
[tablaConfig removeFromSuperview];
selector = true;
}
I also got this problem and I also didn't found that.
I am using NIDropDown custom control tableview shows but i cant select or scroll.
problem was that when I do [anySuperView addSubview:anyTableView];
My anySuperView's size (75) was less than my anyTableView's size (400).
so I made superViews size (500) and my problem solved.
Any body who can give more technical detail about this will be appreciated.
So late answering this because I found no solution anywhere else
I'm not quite sure what you're looking for. But if you want the cell to be highlighted when selected, you need to add this line of code to your tableView: cellForRowAtIndexPath:
yourcell.selectionstyle = UITableViewSelectionStyleBlue
You can also use UITableViewSelectionStyleGray. If you want to perform some actions when they select the row, you can use the tableviewdelegate methods:
Managing Selections
– tableView:willSelectRowAtIndexPath:
– tableView:didSelectRowAtIndexPath:
– tableView:willDeselectRowAtIndexPath:
– tableView:didDeselectRowAtIndexPath:
UITableViews can be tricky but stuff like this can be easily found in Apples references at:
http://developer.apple.com/library/ios/navigation/
Just Search for the class or delegate or whatever you are using.
It had a similar problem. I solved it by adding my table view farther down down the line and setting up a flag to keep track if it was installed. In your code, move [paintView addSubview:tablaConfig]; into the btnTablaConfig: method, executing it the first time the table is expanded. The problem seems to involve view init code timings.
Related
I am trying to implement UIPickerView and I have almost done it. But when I click on text field, picker view appears behind the text field. Here are the snapshots before and after showing picker view.
Before clicking on text field.
After clicking on the text field.
Here you can see that picker view is behind the text field. I want it to be on top.
EDIT Here is the code I am using to show picker view:
-(void) showPickerView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.50];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.view bringSubviewToFront:self.picker];
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if(iOSDeviceScreenSize.height == 480)
{
CGRect frame = self.picker.frame;
frame.origin.y = 151.0;
self.picker.frame = frame;
frame = self.toolBar.frame;
frame.origin.y = 107.0;
self.toolBar.frame = frame;
}
else if(iOSDeviceScreenSize.height == 568)
{
CGRect frame = self.picker.frame;
frame.origin.y = 239.0;
self.picker.frame = frame;
frame = self.toolBar.frame;
frame.origin.y = 195.0;
self.toolBar.frame = frame;
}
[UIView commitAnimations];
}
In your view hierarchy the textfield may be above pickerview. If you are using xib/storyboard then select pickerview and from menu select Editor>Arrange>Sent to Front.
If you are using code for creating all ui elements add pickerview after adding textfield. or
try
[self.view bringSubViewToFront:pickerView];
use
[self.view bringSubViewToFront:pickerView]
you did't get than please share your code for more explanation we will help..
I solved the issue. In fact it was a plum mistake. I placed the pickerView before other views. So when it appears on screen, it appears behind the textfield. I had to put it at the bottom place in my .nib file.
In iOS, the view added before will go behind other views. I missed this concept.
My storyboard elements are subviews of containerView and containerView is a subview of the main view. I am trying to resize the height of my container view when an ad is available to show but I cannot get that to work. I am able to offset the view up, but I am not able to resize it. I have seen quite a bit a posts about this, but all suggestions I've read basically say to confirm Autolayout is not checked. I have confirmed that Autolayout is not checked in each element of my storyboard but still am not having success with this. The ad banner (placed just off screen at [0, 480] pops up nicely from the bottom just like I want it to, but it covers up my storyboard elements which is just plain UNACCEPTABLE. I will not stand for this! I need some help guys and gals…Please see code below:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (_bannerIsVisible == NO)
{
NSLog(#"Ad Loaded");
[UIView beginAnimations:#"animateAdbannerOn" context:nil];
//_containerView.frame = CGRectOffset(_containerView.frame, 0, -50);
_containerView.frame = CGRectMake(_containerView.frame.origin.x,
_containerView.frame.origin.y,
_containerView.frame.size.width,
_containerView.frame.size.height-50);
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
Try it like this:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (_bannerIsVisible == NO)
{
NSLog(#"Ad Loaded");
[UIView beginAnimations:#"animateAdbannerOn" context:nil];
//_containerView.frame = CGRectOffset(_containerView.frame, 0, -50);
CGRect frame = CGRectMake(_containerView.frame.origin.x,
_containerView.frame.origin.y,
_containerView.frame.size.width,
_containerView.frame.size.height-50);
[_containerView setFrame:frame];
CGRect frame2 = banner.frame;
frame2.origin.x = 0;
frame2.origin.y = -50;
[banner setFrame:frame2];
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
You have just changed the frame of your containerView. This does not in any way change the frames of the subviews of containerView. You either have to make containerView a scrollview or change the frames of every component.
I wonder if somebody here knows how I can slide the views in my application. When I'm in a view, I want to slide to another view like in "The Magazine". (see image)
Hope somebody can help me.
Image:
http://bildr.no/view/1361377
As far as I know, there is no "canned" transition that does a slide over. I've implemented it like this:
-(void)SlideInController:(RDSlideController *) next {
next.presentingVC = self;
next.view.frame = CGRectMake(self.view.frame.origin.x + 320, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[self.view.window addSubview:next.view];
[UIView animateWithDuration:slideTime animations:^{
next.view.frame = self.view.frame;
} completion:^(BOOL finished) {
self.view.window.rootViewController = next;
}];
}
-(void)SlideOut {
RDSlideController *prev = self.presentingVC;
prev.view.frame = self.view.frame;
[self.view.window insertSubview:prev.view belowSubview:self.view];
[UIView animateWithDuration:slideTime animations:^{
self.view.frame = CGRectMake(self.view.frame.origin.x + 320, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
self.view.window.rootViewController = prev;
}];
}
In this example, I made a controller class (RDSlideController) that was the superclass of my other controllers, so that they would all have the presentingVC property and access to the various slide in and out (and up and down) methods that I wrote. This should give you an idea of how to do this.
Take a look at UIPageViewController
Here is a link to the doc. Starting with iOS5, it supports the page curl transition. And in iOS6, they added the slide like you have on your screenshot.
If you need to support earlier version, you will most likely need to create your own animation (using CAAnimation).
I have a UIScrollView at the very top (just below the navigation bar) of a UITableViewController using Storyboards. The UIScrollView's default size is 320x50. When the user holds the scrollView for at least 1 second, I want the UIScrollView to get twice as big (320x100) in order to show additional details with an animation. The UITableView right below it should animate with it if possible and move down 50.
Holding the UIScrollView for at least 1 second when it's in the bigger setting will result in the opposite animation, and the UIScrollView will animate back to its original size.
How would I do this? Thank you ahead of time! Here's what I have so far:
- (void)viewDidLoad {
[super viewDidLoad];
self.featureScrollExpanded = NO;
UILongPressGestureRecognizer* featureHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector (longHold:)];
[featureHold setDelaysTouchesBegan : YES];
featureHold.minimumPressDuration = 0.6;
featureHold.numberOfTouchesRequired = 1;
[self.featureScrollView addGestureRecognizer:featureHold];
[featureHold release];
}
- (void)longHold:(UIGestureRecognizer*)sender {
if (self.featureScrollExpanded==NO) {
self.featureScrollExpanded=YES;
//make it bigger
}
else {
self.featureScrollExpanded=NO;
//make it smaller
}
}
Do an animation:
CGRect frame = yourScrollView.frame;
frame.size.height += 50;
[UIView animateWithDuration:0.6
animations:^{
yourScrollView.frame = frame;
} completion:^(BOOL finished) {
//do your other animation here if you want to
//or do them both together and lose this block
}
];
Or if you want it a bit more with an overview:
CGRect frame = yourScrollView.frame;
frame.size.height += 50;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.6];
[self.yourScrollView setFrame:frame];
[UIView commitAnimations];
I can change the position of delete button when tableviewcell in the edit style, use following code
- (void)didTransitionToState:(UITableViewCellStateMask)state
{
[super didTransitionToState:state];
if(state == UITableViewCellStateShowingDeleteConfirmationMask)
{
for (UIView *v in [self subviews])
{
if([NSStringFromClass([v class]) isEqualToString:#"UITableViewCellDeleteConfirmationControl"])
{
NSLog(#"find");
CGRect f = v.frame;
deleteView = v;
NSLog(#"delete view %#",[deleteView description]);
v.backgroundColor = [UIColor grayColor];
v.frame = CGRectMake(200, 10, f.size.width, f.size.height);
UIControl *vs = [[v subviews]objectAtIndex:0];
CGRect fs = vs.frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1];
fs.origin.x -=20;
vs.frame = fs;
[UIView commitAnimations];
}
}
}
}
use this way I can change the position of delete button. But each time the delete button appears, it moves in from the right side of my tableviewcell with animation, and finally it located at the position I specified..... I just want to set the button frame before it appears, but now i have no idea. my english is poor ...thanks everybody ..thanks in advance
There are two messages: tableView:willBeginEditingRowAtIndexPath: and tableView:didEndEditingRowAtIndexPath:.
I think you can use the delegate to update the appearance of the table view appropriately.