I have an UIView named _containerView and inside this UIView I have a custom UITextView named _codeTextView. When the app is loaded, these views occupies the whole screen, however, when the keyboard appears, I would like the screens to resize.
I have to following method when the keyboard appears:
- (void)keyboardAppears:(NSNotification *)notification
{
_containerView.frame = CGRectMake(0, 0, 320, 216.0f);
_codeTextView.frame = CGRectMake(0, 30, 290, 216.0f);
}
The containerView gets resized properly however, the _codeTextView in it does not resize and I really have no clue why it's not resizing. I've already tried changing various options and it's driving me crazy :(
Could anyone help me?
Thanks in advance!
I just created a project with the scenario you described. setFrame worked for all views with Autolayout disabled, but not with Autolayout enabled.
Do you have Autolayout enabled for that View Controller? setFrame does not work well with autolayout.
You'll have to use constraints to programmatically adjust your views.
(answer from: Can I use setFrame and autolayout on the same view?)
You can find some help here: http://nszombie.com/2010/12/08/ConstraintBasedLayout.html
Related
I am new for cocoa OSX application might be this question is simple but i try my best to find out this issue and at the end i asking question here.
I am creating NSWindowViewController and in side it i Used NSTableview with Customcell. In customeCell i used NSView (customView) and all Cell IBOutlet put in side NSView. When First time that NSWindowViewController load that show fine but after close the window and again i open it. its NSTextField IBOutlet change its position top to bottom of the cell.
I try to find this some property change but did not fix it i attach its screen example what was happen with my cocoa osx Application.
I notice that this happen when i used following code for setting NSview's background color from property Inspector i setting NSView Core animation like.
And set background color in viewForTableColumn like:
cellView.bgview.layer.backgroundColor = [NSColor whiteColor].CGColor;
Color set properly and all working fine when i reload table view that top label going to bottom and that will display revers UI order for cell as i show in my question.
And i tested with if i remove NSView setting background color code as i mention above then working perfect no re-order and all things. I am not using Auto-layout.
So after then i create custom subclass of NSview for setting color like following:
- (void)drawRect:(NSRect)dirtyRect {
[[NSColor whiteColor] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
// Drawing code here.
}
I remove my old code and use this one for setting background by creating NSView subclass and my issue fix.
I have seen many questions in this forum which gives answer to this topic "UIButton inside a UIView, when animated doesn't work", but after having tried out the answers like
a) UIViewAnimationOptionAllowUserInteraction to the options
b) subView.setUserInteractionEnabled = YES
c) [button addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
none of them is working for me :-(
Here is the scenario. App is in landscape mode and a UIView called menuView is placed at x=480,y=0. Its height=200 and width=150. So, when I tap the button on the top right corner, the following code is executed
- (IBAction)showMenu {
[menuView setUserInteractionEnabled:YES];
[optionsButton setUserInteractionEnabled:YES];
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.view.frame = CGRectOffset(self.view.frame, 0, 200);
}
completion:NULL];
}
Output?: View is appearing, but optionsButton inside the menuView is not clickable. I hooked up to an event, did an NSLog(#"Options button clicked"), but nothing happens :-(
Please tell me what I am doing wrong?
Update: When I place the subview that is "menuView" inside the self.view, then upon running and click the optionsButton, I get the NSLog message. Only if I specify the origin.x of menuView to be 480 and above, it doesn't work.
If you can see the UIButton, its userInteractionEnabled (YES by default!) is set, and its superview's userInteractionEnabled in the whole hierarchy is YES - you should be able to interact with it.
An animation will never change your userInteractionEnabled property! So what you are doing there is simply unnecessary. If you try to enable interaction during animation - that's a different story and is just an option passed to the animation message.
So if that's not your problem (and is probably not), then I guess one of the superview's frame is cropping the UIButton!
Now you see, if a UIButton (or any UIView) is outside a UIView's frame, it can still be visible, unless clipsToBounds is set on the superview.
And the outcome of that situation is: You can see me, but you can't touch me.
In my case missing a constraint on the height of the containing view caused the view height to be 0. Buttons were visible, below the view, but untouchable.
For me it was all about an overlooked mistake in the animation code itself. Where my new height was being called I was actually calling my new width, and where my new width was being called I was actually calling my new height, therefor causing the UIView to be super long yet super narrow, thus pushing all content within the center of view, outside of the view reach.
Change your UIViews background color to Red so that you can actually see where it animates to.
If your UIView is within another view, turn on clipSubviews so that you only see what is actually enabled within the subView.
Run your project.
If your UIView is not its normal height and width, more than likely you have overlooked some code in your animation call.
Make sure that your x, y, width, height are being shown in the correct orders within the animation code.
In my case, it seems like my animated transitioning is not yet completed. I forgot to to put completeTransition:Bool at the end of my animateTransition:context method.
I'm working on an iPad app that lets you control different things in a prototype of an intelligent house. For example it lets you turn lights on and off. For this, I have made a UIImageView that shows the floor plan of the house and added UIButtons as subviews for each lamp that can be toggled.
As you can see the buttons are placed perfectly on the floor plan using the setFrame method of each UIButton. However, when I rotate the iPad to portrait orientation, the following happens:
The buttons obviously still have the same origin, however it is not relative to the repositioning of the image.
The floor plan image has the following settings for struts and springs:
and has its content mode set to Aspect Fit.
My question is
how do I dynamically reposition each UIButton, such that it has the same relative position. I figure I have to handle this in the {did/should}AutorotateToInterfaceOrientation delegate method.
It should be noted that the UIImageView is zoomable and to handle this I have implemented the scrollViewDidZoom delegate method as follows:
for (UIView *button in _floorPlanImage.subviews) {
CGRect oldFrame = button.frame;
[button.layer setAnchorPoint:CGPointMake(0.5, 1)];
button.frame = oldFrame;
button.transform = CGAffineTransformMakeScale(1.0/scrollView.zoomScale, 1.0/scrollView.zoomScale);
}
Thank you in advance!
I find the best way to layout subviews is in the - (void) layoutSubviews method. You will have to subclass your UIImageView and override the method.
This method will automatically get called whenever your frame changes and also gets called the first time your view gets presented.
If you put all your layout code in this method, it prevents layout fragmentation and repetition, keeps your view code in your views, and most things just work by default.
I want to change the picker view bakground color. I try this way but not worked.
doublePicker.backgroundColor = [self RGBColorR:85 G:17 B:92];
- (UIColor *)RGBColorR:(double)red G:(double)green B:(double)blue {
return [UIColor colorWithRed:(red/255.00) green:(green/255.00) blue:(blue/255.00) alpha:1.00];
}
I want to do picker view like in picture. How can I do this? Thanks for your reply.
you can add subviews over certain areas of your pickerview..
use:
[picker addSubview: coverView]; //adding subviews to different area of the picker
you're going to find yourself playing with alot of CGRect to get thing to fit properly. If you want to change the entire thing you're going to have to override some methods that handle the touch events etc..
this tutorial might help you create a custom picker
https://developer.apple.com/iphone/library/samplecode/UICatalog/
You cannot change the appearance of UIPickerView, even the size, it's the most unchangeable UI element in iOS. Best you can do is build custom by yourself, using UIScrollView with paging enabled.
Not sure why this happens or how to stop it, my UIToolBar on the details viewcontroller is only visible during portrait view. I want it visible at all orientations. How do I do that? Thank you.
I encountered the same problem by just dragging a UIToolBar on to my view and docking it on the top of the window. It showed up in landscape but not portrait. Interface Builder - at least the one embedded in Xcode 4 - doesn't seem to do the right thing with the resize masks.
While Kshitiz's answer above will work, it has a couple of flaws. As coded, it does not support all four orientations. More importantly, it's not resolution independent.
A better solution is briefly described in enamrik's comment, so credit should go to him/her. Here are the steps:
Select the tool bar in Interface Builder.
Open the Size inspector.
In the Autosizing box, select the left, right and top "i-beams" on the exterior of the square. This keeps the position of the toolbar fixed relative to the sides of the view when the view is resized.
Inside the Autosizing square, select the horizontal line with arrows on both ends. This causes the size of the toolbar to change in sync with the parent view.
in your this function of view controller reset view frame bro
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
self.view.frame = CGRectMake(0, 0, 703,768);
} else {
self.view.frame = CGRectMake(0, 0, 768, 1024);
}
return YES;
}
and your tool bar frame too
good luck
Faced the same problem when I add UIPickerView programmatically and add UIToolBar for the PickerView. Just need to add [.flexibleWidth,.flexibleHeight] for the UIPickerView. eg:-
let statTypePicker = UIPickerView()
And then add
self.statTypePicker.autoresizingMask = [.flexibleWidth,.flexibleHeight]