I have a basic subview that slides up 80 from the top of the screen when a button is pushed. I’ve created another class – AdvancedView – that inherits from UIView. What I would like to do Is first of all, push all the code that’s responsible for creating this subview into it’s own class: AdvancedView. I would then like to somehow set it to where the top 100 of the subview is show showing when the main view loads. I’m going to put a button at on the top showing portion of this subview that will toggle it up and down (I know how to code the button). Here is the code that I need to put into AdvancedView and have the top 100 showing when the main view CalcViewController loads:
#import "CalcViewController.h"
#import "CalculatorBrain.h"
#import "AdvancedView.h"
@property (nonatomic, strong) AdvancedView *myNewView;
@synthesize myNewView = _myNewView;
- (AdvancedView *) myNewView
{
if (!_myNewView) _myNewView = [[AdvancedView alloc] init];
return _myNewView;
}
- (IBAction)subView {
self.myNewView.backgroundColor = [UIColor groupTableViewBackgroundColor];
self.myNewView.frame = CGRectMake(0,489, 320, 200);
[self.view addSubview:self.myNewView];
float bottomYOfDigitBeingDisplayed = 75;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.myNewView addSubview:button];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:0.0];
[UIView setAnimationDuration: 1.0];
self.myNewView.frame = CGRectMake(0, bottomYOfDigitBeingDisplayed, 320, 400);
[UIView commitAnimations];
}
Your UIView subclass could look like this
.h
.m
Your UIViewController could look like this