Changing the height ordering of widgets in an iPhone app - iphone

In my app I have added a UIView as a new subView, however it covers up a UISegmentedControl. I was wondering if there's a way to move the UISegmentedControl back on top so its fully visible?

If you take a look at the docs for UIView you'll find that there are several options:
-insertSubview:belowSubview:
-insertSubview:atIndex:
-bringSubviewToFront:
-exchangeSubviewAtIndex:withSubviewAtIndex:
Also, take a look at View Architecture Fundamentals for an overview of how views relate to each other.

Related

Swipe Section Page - Swift 3

I want to make the horizontal swipeable page like YouTube. Is there an object in XCode for this? How do I have to do it? I did not find a tutorial about it. Sorry for my English.
Like this
There are tons of components already made for this in the internet, you can try looking at the cocoacontrols site.
If you still want to write your own code for this, one way is writing a custom UIView subclass. The YouTube feature looks very simple and as far as I can guess, they can use two separate UIView subclasses: one for the menu and one for the pages, just as a container.
For the menu you can use UIStackViews or a single UIViews with UIButtons for the page's titles and another view for the selection effect that moves with the UIButton's touch event. This view should provide a delegate or any notification system that fits better to you in order to notify the container that needs to load the right UIViewController's view inside the container.
The container can be a UIView that loads the view property from the UIViewController subclass on demand. Make sure to add the loaded view controller as a child of the parent view controller, otherwise you will loose some important features.
I hope it can help you to start.

How to auto arrange all sub views?

I have a UITextView at the top of a UIView, below many UIControls are there like buttons, table view... Possibilities are user can give multiple lines in UITextView, in that case I have to expand(increase height) for UITextview to show two lines, If UITextview height increase every other controls should go down accordingly, How to do it in iOS ? I heard android they are auto arranging easily, Is there any way to do like this in iOS?
Where should I concentrate? Any ideas will be helpful. Thanx.
You should use autolayout for achieving this.
raywenderlich autolaout
developer.apple.com
Auto Layout video tutorial
About Cocoa Auto Layout
This tutorial helps you to understand autolayout in a better way.
You could look at auto layout, it's available from ios6 onwards. It will allow you to easily (some even non programmatically) specify constraints to be maintained while the view hierarchy is being displayed. For a good tutorial see this.
If you are working on iOS5 or below I would recommend the following :
I am assuming that all your views are direct children of the textView, even if that isn't the case the grandchildren views (and further ancestors) will move automatically once their parent moves down.
for (UIView* view in yourTextView.subviews)
view.transform = CGAffineTransformMakeTranslation(0,Y_DELTA_VALUE);
//Y_DELTA_VALUE is the amount you want to move the subviews down by, the
//(amount of height the textView increases by)/2

Really cool way to create custom UITabBar for iPhone app?

I am doing a lot of researching lately about how to get a different looking with nice effects UITabBar on my iPhone app, but unfortunately I am only finding things on how to replace background color etc.
Well, I've checked out this app called Momento which is pretty cool and presents a very slick tabBar:
So there are a couple of elements here I would like to ask you guys if you could help me by giving me the right directions on how to get a similar effect :)
Arrow above items: as you can see this app has this animated arrow that runs above the selected item with a very smooth animation.
Selected Stated of the item's image is not that blue-ish default one neither the default state which displays in a different shade of brown and gray version.
nice Items separators with beveled vertical lines.
different background image for the tabBar
different height for the tabBar
At this point after some research I am able to set the height and background image by subclassing UITabBarController but I'm still not sure on how to accomplish the other items specially the first one related to the nice arrow effect.
How do I do this? Please clarify what can or can't be done by subclassing the UITabBarController and specially if can be done in Interface Builder.
There's a project on github called BCTabBarController that aims to mimic the tab bar used in Twitter for iPhone. It's got some of the things you're looking for, and should give a great starting point.
Both of these are good answers, but both libraries have problems: BCTabBarController doesn't know how to create the "blue" highlighted version of a tab bar icon; and iDevRecipies doesn't send events to child viewcontrollers nor resize the navigation bar on rotate.
Be warned: custom nav bars are a lot of trial-and-error debugging (as I have found).
Simply use a UIView with TabBar width and height.Add custom background image and custom buttons on the view.Set the fileowner of the view as AppDelegate.Now you can simply connect the IBActions with the buttons.The Custom view can be placed over the tabbar by addSubView to the TabBar controller's view.You can switch between viewcontrollers by using the setSelectedIndex method of tableviewcontroller in the button action.

How to realize the same effect like iPhone's homescreen

I want to add some custom buttons and realize the same effect like the iPhone's home screen. What I can think of is to calculate the position of each button and add them to the view. Are there any other ways to do this? e.g. add buttons to the tableview
Check TTLauncherView from Three20,
I realized the same view of the thumbnails in the photo app (which in principle differs only because of the background color and the rounded effect of the buttons) using a custom cell (with 4 UIButtons inside) in a normal tableview.
In my case, this is because I need to scroll up and down, in your specific case there should be a way to "lock" the table from scrolling. By the way, for this reason, it could be simpler to design the custom view in the interface builder, it is very quick to design such a view, and then create a custom controller to provide simple methods to assign icons and actions to the UIButtons dynamically.
You could also look at the Three20 libraries as already suggested, it is already implemented, but you app will easily be rejected by Apple if you do so.

iPhone SDK view scrolling not rubber banding or using momentum from swipes

I'm having a fundamental problem with getting scrolling to work normally on my iPhone app. I have two views, each created in IB (although I've tried this programmatically and it makes no difference) which scroll very sloppily. Instead of the scrolling that we're used to (which is smooth and continues to scroll and eventually dampen and rubber band at the top/bottom), my scrolling only scrolls as long as my finger is in contact with the view. Swiping down quickly on a view has no more effect than swiping slowly. And when you scroll beyond the top or bottom, the view just stays there scrolled with empty area above/below.
One of my views is a UITableView and the other is a UIScrollView. Both have exactly the same problem and are in different XIBs, coupled to different classes, so this is why I think I'm missing a key concept in general.
My UITableView is a child to a UIView (since there is also a nav bar at the top) with my UIViewController's view connected to the UIView. The referencing outlets datasource and delegate are both hooked to the UITableView. Nothing is subclassed here aside from the ViewController of course which has overrides to populate the table.
In the second instance, I again have a non-subclassed UIView which my UIViewController's view is connected to. I have a subclassed UIScrollView as a child to the UIView and then a have a subclassed UIView (with larger size than the scroll view) as a child to the subclassed UIScrollView. This in itself seems ridiculously complicated to me, but I was not able to get scrolling working at all with fewer than 3 views (again there is a nav bar at the top of the non-subclassed UI-View). I am overriding drawRect: in my UIScrollView, which is putting the content up fine except for this scrolling issue.
Is there something I'm doing wrong organizationally? I've come across many suggestions on stackoverflow and other sites for UIScrollView and none make a difference. And I don't see anyone having scrolling issues with UITableView. I'm not pasting in any code because I would have to post full classes at this point (making the post ridiculously long) and I believe the problems to really lie with the way I'm using IB.
Thanks!!
OK, it turns out that this has nothing to do with UIKit. This code is part of a game I'm developing using cocos2d and that framework is what is causing the problem. For those who are developing on cocos2d, you cannot use FastDirector and expect scrolling to work in UIViews. Just remove any code like [[Director sharedDirector] useFastDirector] and everything will be fine.
Some code might help narrow down your problem.
In the mean time, try creating a new project in Xcode using the 'Navigation-based Application' template and take a look at how the navigation controller is being created in MainWindow.xib. Take a look at how the UITableViewController subclass called 'RootViewController' is defined and how the corresponding xib is setup too. You'll notice there is no UIScrollView explicitly defined anywhere but you get scrolling functionality from the tableview controller 'for free'.
This should give you a pretty good starting point down the right path. I question the need for overriding drawRect: without seeing some code or fully understanding your goal.
Take a look at:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html
http://developer.apple.com/iPhone/library/featuredarticles/ViewControllerPGforiPhoneOS/UsingNavigationControllers/UsingNavigationControllers.html