-2

Short pre-introduction to a problem:
I applied to a position of iOS developer. For this position they don't require knowledge of Objective-C or iOS development. The requisites are a good experience with C/C++ and development for Linux platform.

Problem:
After the end of interview I got a task (with words that it's easy to impelement, is it?) and I can't understand whether it's so.
Interviewer has showed me an application on his iPhone that looked like: enter image description here

Pressing/dragging that button leads to appearance of such bar:

enter image description here

He could scroll it and drag on the screen. When he had pressed the control button, bar disappeared.

I want to ask for excuse in advance, because I feel myself like a person who wants his job to be done by others. But I just want understand how I can approach to this problem. Cocoa library is a big and a new beast to me. Which classes/elements from it is it better to use to reach this aim? I programmed before with Qt, Tkinter, WinAPI (gui programming) for desktop but it doesn't help me a lot here.
I need to code something similar like the interviewer has showed me. I tried to find something in the internet similar to this, but without success.

So, I just want to know for which classes it's better to look for in Cocoa library. And, if I failed to take something into consideration I would be glad (happy) to hear your notes.

Thanks in advance for any replies!

SOLVED
I want to thank everyone who replied and didn't leave me to sink into this unknown sea.
After a week of exploring I got what I wanted:

enter image description here

Source code: (I apologize, but I can't copy-paste code from virtual mac os machine)

enter image description here enter image description here

Now I understand how too-wide and silly is my question, but anyway perhaps it helps someone to start out. Also one book helped me a lot.

4

5 に答える 5

4

There is no required understanding of Objective-C, but the interviewer wants you to create a simple application and return it to him? Interesting interview.

As for your question. The classes I see being needed here (aside the AppDelegate and a UIViewController of your choice) are:

UIButton

UIScrollView

UIImageView

The button's use here is obvious. The scrollview is again obvious. The imageview would be the icons inside the scrollview.

于 2013-02-25T15:49:40.463 に答える
1

Have a look at this:

http://www.cocoacontrols.com/platforms/ios/controls/aurosetteview

When you press a button, the items show up and when you press again, it closes.

The source code is within the library. Use it to read up.

For your case, you need to include the scrollview as well.

于 2013-02-25T16:01:13.070 に答える
1

Allright - just to give you some guidance on what to start with and how to proceed so that you don't get lost in the great wide world of cocoa ... And assuming that you are familiar with programming and have some decent experience in the c++ and java worlds ...

Open xcode. Go for blank view based app. Single view application would do. Go for Automatic Reference Counting (ARC).

xcode creates a template for you with an application delegate (which you would not need for this task)

A view controller is created and a xib/nib file for an iPhone view. (ignore the ipad view if any).

Add to your view controllers so called IBAction methods. One for the top button and one for the others. An action is supposed to be called when a button is pressed (and other events which you don't need).

Properly defined you will see that action in the interface builde when editing the xib file. Add a button and connect it with this action (touch up inside would be best I think).

Compile this. When your button is pressed the action is executed. Set a breakpoint there to make sure that it got called.

Now, in this action, you either call a newly created method showScroller and hideScroller. And create those methods.

Now it gets a bit more complicated. In showScroller you would have to ...

  1. create a UIScrollView. (alloc it and init it)
  2. create a number of UIButtons. (no alloc withot its init in objective-c)
  3. set your second IBAction method as target for the buttons.
  4. Position the buttons within the UIScrollView accordingly.
  5. Position the UIScrollView nicely under the top button.
  6. add the UIButtons as subview to the contentview of the Scroll view.
  7. add the scroll view as subview to self.view (that is the underlying view, the grey thing in the interface builder).

In hideScroller you would have to ...

  1. remove the UIScrolView from the view. For that you could either remove all subviews from self.view or you would have to keep a reference to the scroll view within your view controller in some instance variable. Pretty similar to C++ and Java which you know already.

Alternative to the scenario described above you could create all views within interface builder and pre-define the scroll view as hidden in IB (interface builder) and in showScroller and hideScroller you would just have to set its .hidden property to YES or NO. But I've got a guts feelting that with your background you should and could do this programmatically instead of hasseling with how IB connects into your code. In the event that you really run into that trap and don't get the top most button properly connected to your code, then create that button programmatically too.

Ah, I forgot. The right place to create all those UI elements would be the viewDidLoad method of the ViewController class. There is an empty one generated already in your empty xcode template. Just enance it following the [super viewDidLoad]; call.

于 2013-02-25T16:19:47.403 に答える
1

Here you go:

  1. Open XCode and create a new project. Choose iOS Empty Application template.

  2. Go to menu, choose File, New File, Objective-C class. Name it RootViewController and choose a subclass to be UIViewController

  3. Go to your app delegate .m file (If your project name was Test, this file is TestAppDelegate.m). At the top of the file, below the line where it says #import "TestAppDelegate.h" add another line that says #import "RootViewController.h"

  4. In the same file there is a method named:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    at the end of the method but before return YES; statement add the following line:
    self.window.rootViewController = [[RootViewController alloc] init]; 

  5. Now go to your RootViewController.m file that you created in the step 2. and at the top of the file edit the interface to have this one instance variable:

    @interface RootViewController ()
    {
        UIView *menuView;
    }
    @end 

  6. In the same file locate the method named - (void)viewDidLoad and add the following code in it:

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor blackColor];
    UIButton *menuButton = [UIButton buttonWithType:UIButtonTypeCustom]; menuButton.frame = CGRectMake(100, 60, 50, 50); [menuButton setBackgroundImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal]; [menuButton addTarget:self action:@selector(menuButtonTapped:) forControlEvents:UIControlEventTouchDown];
    CGRect menuFrame = CGRectMake(20, menuButton.frame.origin.y + 50, 300, 60); menuView = [[UIView alloc] initWithFrame:menuFrame]; menuView.backgroundColor = [UIColor purpleColor]; menuView.hidden = YES;
    UIButton *menuButtonA = [UIButton buttonWithType:UIButtonTypeRoundedRect]; menuButtonA.frame = CGRectMake(5, 5, 50, 50); [menuButtonA setTitle:@"A" forState:UIControlStateNormal]; [menuView addSubview:menuButtonA];
    UIButton *menuButtonB = [UIButton buttonWithType:UIButtonTypeRoundedRect]; menuButtonB.frame = CGRectMake(65, 5, 50, 50); [menuButtonB setTitle:@"B" forState:UIControlStateNormal]; [menuView addSubview:menuButtonB];
    UIButton *menuButtonC = [UIButton buttonWithType:UIButtonTypeRoundedRect]; menuButtonC.frame = CGRectMake(125, 5, 50, 50); [menuButtonC setTitle:@"C" forState:UIControlStateNormal]; [menuView addSubview:menuButtonC];
    UIButton *menuButtonD = [UIButton buttonWithType:UIButtonTypeRoundedRect]; menuButtonD.frame = CGRectMake(185, 5, 50, 50); [menuButtonD setTitle:@"D" forState:UIControlStateNormal]; [menuView addSubview:menuButtonD];
    UIButton *menuButtonE = [UIButton buttonWithType:UIButtonTypeRoundedRect]; menuButtonE.frame = CGRectMake(245, 5, 50, 50); [menuButtonE setTitle:@"E" forState:UIControlStateNormal]; [menuView addSubview:menuButtonE];
    [self.view addSubview:menuButton]; [self.view addSubview:menuView]; }

  7. Below that method add a new method:

    - (void)menuButtonTapped:(id)sender
    {
        if (menuView.hidden)
            menuView.hidden = NO;
        else
            menuView.hidden = YES;
    }
    

  8. Find some nice png image on the internet that will represent your menu button. Name it menu.png and drag and drop it in your project(inside the "file" menu on the left side)

That's it run the project ;)

于 2013-02-25T16:35:34.000 に答える
0

just read the iphone's beginner book. you have to read some book first. first try to understand basic controls in iphone & basic manipulation in objective c

your above work is very basic.now just you are away from one step and that is read a book, you will get lots of free pdf on net

于 2013-02-25T15:46:04.027 に答える