开发者

How to control UIView in code

As you can see in the screenshot, I added a UIView(named SearchView) in IB 开发者_如何学运维to control in my code.

http://i.stack.imgur.com/cIs3e.png

How can I load the UIView in my code programatically?

Thanks.


FlipView Approach to load UIView Programmatically

In .h file use this code

  @interface MainViewController : UIViewController {
    IBOutlet UIView *secondaryView;
}
- (IBAction)toggleView:(id)sender; //Action for toggle view
- (IBAction)returnView:(id)sender;


@end

In .m

- (IBAction)toggleView:(id)sender {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                               forView:[self view]
                                 cache:YES];
        [[self view] addSubview:secondaryView];
        [UIView commitAnimations];
    }

    //Flips to front when "Done" is pressed
    - (IBAction)returnView:(id)sender {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                               forView:[self view]
                                 cache:YES];
        [secondaryView removeFromSuperview];
        [UIView commitAnimations];
    }

You can check this tutorial http://www.vimeo.com/5653713 if any confusion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜