iOS center button on rotations - ios

I have a UIView that is a subview of another UIView. Within this UIView I have a button that I always want to be centered. The problem I am running into is that, since the subview can change sizes upon rotations, the button gets off centered. Is there a way to get auto-centering?

Try setting the button center as the uiview center like this:
[myButton.setCenter:mySubView.center];
and then set autoresizing mask:
[myButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
Hope it helps.

Turn on auto-layout and center your button. You turn on auto-layout by selecting your view controller and on the right check auto-layout. Here is a picture:

Related

Swift 4 UIButton attach on a View

My problem is the following:
I am practicing in swift 4 and for this I am making an app to show my current position and have a SideMenu.
I have managed to make the lateral menu unfold and close with the + button that is in NavBar, but at the time of add a UIButton to perform other actions the button is superimposed on all layers and does not go with the view.
Attached screenshots of the app, and some views of how I have the storyboard in xcode:
pd: is Swift 4 and the latest version of Xcode
You will need to set your menuView's clipsToBounds property to true it is false by default. When false a view's subviews will be displayed even if they are outside the view's bounds. You're also missing a constraint on your button. Auto layout can determine its x position but not it's y. Add a top, bottom, or centerY constraint.
the button is superimposed on all layers and does not go with the view.
It sounds like the button is probably constrained to View or Google Maps View instead of Menuview, so that the button maintains it's position relative to those views even when Menuview moves. Change the constraints so that the button is constrained to Menuview, and the button should then move when Menuview moves.

UIImageView will not resize to match UIView's frame

I want my background to be an image, so in IB I set a UIImageView with the constraints to be the same size as the its UIView. However, when I select "back" on the UINavigationBar, when the NavControl pops to the previous VC, this is what's there, briefly, before it disappears:
That is, the UIImageView is so big that it is almost double the width of the UIView, so as it slides off-screen to the right, the UIImageView's image drags on before finally disappearing.
I have also tried to do this programmatically, but even if I set the UIImageView's frame to be CGRectMake(0, 0, 100, 100), it still goes off to the left side of the UIView, as if the UIView's origin weren't at the top left corner, but slightly off the screen. Is this possible? How do I make it so the image fits the screen and doesn't go off?
If it's at all relevant, the jpg I'm using is in Images.xcassets and, although I can select it in IB and it appears, the UIImageView's image is white/blank, so in my viewDidLoad method I need to specify self.imageView.image = [UIImage imageNamed:#"hockeyIce.jpg"].
go to Main.storyboard
select the view in question
click Attributes Inspector
scroll down to View, select Mode: Scale To Fill
OK, the solution was to add [self.imageView setClipsToBounds:YES] to my viewDidLoad. It turns out that this is a common problem with aspectFill.

Recreate UITabBar to UIToolbar on select from Photos app

I need to do exactly what the photos app is doing when you press the select button. Basically just hides the UITabBar and presents a UIToolbar. For some reason this seems to be incredibly difficult if you don't want to implement a complete hack. I found a hack if you shrink the height of the UITabBar and change it's alpha to 0 but when you set it's height back to the default the image and text is condensed.
Turns out that I ended up just needing to call [self.tabBarController.tabBar setHidden:YES] to hide the tabBar and instead of using my existing UINavigationController's toolbar I create my own instance of a UIToolbar and add it as a subview of my view controller. Then using autolayout I pinned it to the leading, trailing, and bottom edge of the view. This handles rotation and other issues.

UIScrollView won't respond to AutoResizing

I have UIScrollView that is a subview on my view controller, in this scroll view I have UIView on top (the blue square) and a UITableView on the bottom (the light grey square). I also have a UIView that is acting like NavigationBar (the dark blue color bar), he is outside of the scroll view.
The view controller hirarchy is:
- view
- UINavigationBar
- UIView (as navigation bar)
- UIScrollView
- UIView
- UITableView
My problem is that something pushs the UIScrollView scroller down, but the UIScrollView y is where it should be, I don't know what causing it, also tried every AutoResizing mask combination, but without success, it just won't move. I also canceld AutoResizingSubviews and set AutoResizingMask to UIViewAutoResizingNone.
In the picture the scrollview is scrolled all the way to the top, you can see that the scroller itself is located down from the scrollview top. also I have a spare in the bottom exactly as the size of the padding in top.
What can I do to fix it?
In iOS 7 and xcode 5 there is new property for viewcontroller that perform such action, if dont want to see that you have to uncheck that property and then the scrollview will work fine.
In the layout section, uncheck the Adjust Scroll View Insets option and viola it will work just fine
Update: Use this code.
self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;

How do I make a button slide to reveal like the UITableView delete confirmation button?

I would like to re-create the animation of the delete confirmation button that Apple uses in the default implementation of UITableView. I want to create this button and animation in my own custom view area, but haven't been successful in finding a proper view transition or animation. Here is a picture of the reveal animation half way through:
And here is a picture of the animation after it has finished:
These are screenshots from a YouTube video that shows how the button animation is supposed to look.
Thanks!
Basically,
1) Put a button inside a view of the same size as the button, with the autoresizing masks of the button set to force it to not shrink when the view changes size, and have a left flexible margin.
2) Animate the view's frame to change from 0 width to full width while moving from x origin to (x - view width) origin.
As the view grows the button will be revealed. The view should have clipToBounds set to yes.

Resources