Uiscrollview inside uitabbarcontroller?


#1

Hello,

Ii cant understand how to make a view with a uiscrollview and insert it in a tabbarcontroller. Anyone can help me with this?
Like keeping the hypnosis keeping scrolling like it was in the standalone example.

Can anyone explain me?

Regards


#2

Can anyone help me here please? i have searched the documentation buti can’t figure how to do this programaticly. using a xib i have no problems…

my code:
appdelegate.h

#import <UIKit/UIKit.h>
#import "area1.h"
#import "area2.h"


@interface subviewsAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) IBOutlet UIWindow *window;

@end[/code]

appdelegate.m:
[code]@implementation subviewsAppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    [[self window] setRootViewController:tabBarController];
    
    NSMutableArray *x = [NSMutableArray array];
    
    [x addObject: [[[area1 alloc] init] autorelease]];
    [x addObject: [[[area2 alloc] init] autorelease]];
    
    [tabBarController setViewControllers:x];
    
    [tabBarController release];
    
    [[self window] makeKeyAndVisible];
    return YES;
}[/code]

area2.h
[code]#import <UIKit/UIKit.h>
#import "imageScrollProgramaticamente.h"

@interface area2 : UIViewController
{
    UIScrollView* scrollView;
}

@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;


@end[/code]

area2.m
[code]#import "area2.h"

@implementation area2

@synthesize scrollView;

- (id)init
{
    if(self = [super init]) 
    {
        UITabBarItem *tbi = [self tabBarItem];
        [tbi setTitle:@"area2"];
        
        
        
    }
    
    return self;
}

- (void)viewDidLoad
{
 [super viewDidLoad];
    imageScrollProgramaticamente *isp = [[imageScrollProgramaticamente alloc] initWithFrame:CGRectZero];
    [self setView:isp];
    [isp setBackgroundColor:[UIColor orangeColor]];
    [isp release]; 
   
    

}

imagescrollprogramaticamente.h

[code]#import <UIKit/UIKit.h>

@interface imageScrollProgramaticamente : UIScrollView{

}
[/code]

imageprogramaticamente.m

[code]#import “imageScrollProgramaticamente.h”

@implementation imageScrollProgramaticamente

  • (id)initWithFrame:(CGRect)frame
    {
    self = [super initWithFrame:frame];
    if (self) {
    // Initialization code

    }
    return self;
    }

  • (void)drawRect:(CGRect)rect
    {
    //what rectangle am i filling?
    CGRect bounds = [self bounds];

    //where is the center?
    CGPoint center;
    center.x = bounds.origin.x + bounds.size.width / 2.0;
    center.y = bounds.origin.y + bounds.size.height /2.0;

    //from the center how far out of a corner?
    //float maxRadius = hypotf(bounds.size.width, bounds.size.height) /2.0;

    //create a string
    NSString *text = @“apple”;

    //get a font to draw it in
    UIFont * font = [UIFont boldSystemFontOfSize:200];

    //where am i going to draw it?
    CGRect textRect;
    textRect.size = [text sizeWithFont:font];
    textRect.origin.x = center.x - textRect.size.width / 2.0;
    textRect.origin.y = center.y - textRect.size.height / 2.0;

    //set the fill color of the current context to black
    [[UIColor blackColor] setFill];

    //draw the string
    [text drawInRect:textRect withFont:font];
    }

@end
[/code]

now… how can i make this imagescrollprogramaticamente…scroll?

Regards


#3

Well, you don’t need to subclass UIScrollView.

In “area2” (which you should name ScrollViewController or something like that), override loadView (not viewDidLoad) like so:

- (void)loadView
{
    UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    HypnosisView *v = [[HypnosisView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024)];
    [sv addSubview:v];
    [sv setContentSize:CGSizeMake(1024, 1024)];
    [self setView:sv];
}

#4

wow so simple!
what about the zoom? how to make it work too?