Landscape mode

Discussion in 'iOS Development' started by hobofan, Aug 12, 2008.

  1. hobofan

    hobofan New Member

    Joined:
    Jun 1, 2008
    Messages:
    68
    Likes Received:
    0
    I want to develop a application in wich uses Landscape mode. I tried to change the UiNavBar size but then the buttons are half offscreen :-(

    I would be relaly glad if someone could explain to me how to dow it or give me the link to the source of an app htat uses this feature
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    setRotation
  3. Yongkykun

    Yongkykun Member

    Joined:
    Dec 11, 2007
    Messages:
    536
    Likes Received:
    11
    Device:
    iPhone 4S (Black)
    While you're at it, is there a way you can make the springboard able to rotate to landscape mode as well?
    Just a thought though...
  4. hobofan

    hobofan New Member

    Joined:
    Jun 1, 2008
    Messages:
    68
    Likes Received:
    0
    not directly

    there's a theme called "2.0 Horizontal" wich makes it a bit like that.

    it would be possible f u have the code of the springboard.app

    edit: @gojhonnyboy: could u please provide a bit mor information, searched the setRotation everywhere, but i can't find any good information about it
  5. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    idk if this helps, as i dont know if it has changed since 1.X but here's a tutorial on how to use screen orientation for 1.X--

    7.13. Orientation Changes
    The iPhone is retrofitted with hardware to sense its state in the surrounding environment. One sensor in particular, the accelerometer, is able to determine the orientation that the iPhone is being held at. How to read the orientation and what to do with it when it's changed are important for applications that need to provide landscape mode support.

    7.13.1. Reading the Orientation
    The orientation of the iPhone can be read using a static method named deviceOrientation, found in the UIHardware class:

    int orientation = [ UIHardware deviceOrientation: YES ];



    This method returns one of six different possible orientations identifying how the iPhone is presently being held.

    Orientation Description
    0 kOrientationFlatUp: Device is laying flat, as if face up on a surface
    1 kOrientationVertical: Device is held vertically, rightside-up
    2 kOrientationVerticalUpsideDown: Device is held vertically, upside-down
    3 kOrientationHorizontalLeft: Device is tipped to the left on its side
    4 kOrientationHorizontalRight: Device is tipped to the right on its side
    5 kOrientationUnknown: Device state unknown; sensor failure?
    6 kOrientationFlatDown: Device is laying flat, as if face down on a surface




    The sensor can be read when the application first starts up, but what's more useful is to know when the orientation has been changed. A change in the orientation is reported automatically to the UIApplication class, the class your GUI application is derived from. A method named deviceOrientationChanged can be overridden to intercept this event.

    - (void)deviceOrientationChanged

    Please Register or Log in to view images

    GSEvent *)event {
    int newOrientation = [ UIHardware deviceOrientation: YES ];

    /* Orientation has changed, do something */
    }



    For example, if the value returned corresponds with a landscape mode (kOrientationHorizontalLeft or kOrientationHorizontalRight), the application can take the appropriate steps to switch to landscape. One way to do this is to create separate UIView classes to service portrait and landscape views individually. The two views could then be transitioned back and forth as the orientation is changed:

    [ transitionView transition: 0
    fromView: portraitView toView: landscapeView
    ];



    7.13.2. Rotating Objects
    The UIView base class supports a method named setRotationBy that allows nearly any display object in UIKit be rotated to accommodate different orientations.

    [ textView setRotationBy: 90 ];



    The argument provided is used to specify the angle, in degrees, to rotate the object.

    Not only will objects need to be rotated to match the orientation of the iPhone, but the status bar must also be rotated. Use the setStatusBarMode method, as discussed in Chapter 3.

    [ self setStatusBarMode: 0 orientation: 90 duration: 0
    fenceID: nil animation: 0 ];



    Depending on whether objects are being rotated to accommodate a left turn or a right turn of the iPhone, specify a value of either 90 or -90 degrees, respectively.

    The object's window will be resized to accommodate the orientation of the object, so the object's origin point also shifts. For example, to display a text view in landscape mode, use a frame defining a landscape resolution.

    CGRect textRect = CGRectMake(-90, 70, 480, 300);
    textView = [ [ UITextView alloc ] initWithFrame: textRect ];
    [ textView setRotationBy: 90 ];
    [ self addSubview: textView ];



    7.13.3. Example: Turning the World on Its Side
    In Chapter 3, one of the very first examples we introduced you to was the "Hello, World" application. We'll use this basic example to illustrate a simple landscape screen rotation. The following code draws the "Hello, World" application on its side, using a landscape mode status bar and rotating the text box to match.

    To compile this example, use the tool chain on the command line as follows:

    $ arm-apple-darwin-gcc -o MyExample MyExample.m -lobjc \
    --framework CoreFoundation -framework UIKit



    Example 7-27 and Example 7-28 contain the code.

    Example 7-27. Orientation example (MyExample.h)
    #import <CoreFoundation/CoreFoundation.h>
    #import <UIKit/UIKit.h>
    #import <UIKit/UITextView.h>

    @interface MainView : UIView
    {
    UITextView *textView;
    CGRect rect;
    }
    - (id)initWithFrame

    Please Register or Log in to view images

    CGRect)_rect;
    - (void)dealloc;
    @end

    @interface MyApp : UIApplication
    {
    UIWindow *window;
    MainView *mainView;
    }
    - (void)applicationDidFinishLaunching

    Please Register or Log in to view images

    NSNotification *)aNotification;
    @end





    Example 7-28. Orientation example (MyExample.m)
    Code View:
    #import "MyExample.h"

    int main(int argc, char **argv)
    {
    return UIApplicationMain(argc, argv, [ MyApp class ]);
    }

    @implementation MyApp

    - (void)applicationDidFinishLaunching

    Please Register or Log in to view images

    NSNotification *)aNotification {
    window = [ [ UIWindow alloc ] initWithContentRect:
    [ UIHardware fullScreenApplicationContentRect ]
    ];

    CGRect rect = [ UIHardware fullScreenApplicationContentRect ];
    rect.origin.x = rect.origin.y = 0.0f;

    mainView = [ [ MainView alloc ] initWithFrame: rect ];
    [ self setStatusBarMode: 0 orientation: 90 duration: 0 ];

    [ window setContentView: mainView ];
    [ window orderFront: self ];
    [ window makeKey: self ];
    [ window _setHidden: NO ];
    }
    @end

    @implementation MainView
    - (id)initWithFrame

    Please Register or Log in to view images

    CGRect)_rect {

    if ((self == [ super initWithFrame: _rect ]) != nil) {
    rect = _rect;

    CGRect textRect = CGRectMake(-90, 70, 480, 300);
    textView = [ [ UITextView alloc ] initWithFrame: textRect ];
    [ textView setRotationBy: 90 ];
    [ textView setTextSize: 18 ];
    [ textView setText: @"Hello, World!" ];
    [ self addSubview: textView ];
    }

    return self;
    }

    - (void)dealloc
    {
    [ self dealloc ];
    [ super dealloc ];
    }
    @end







    7.13.4. What's Going On
    When the application instantiates, a main view object is created, and its initWithFrame method is called.

    The main view creates a UITextView class with a resolution of 480x300, for landscape mode.

    The text view's setRotationBy method is invoked to rotate the object 90 degrees clockwise. It is then added to the screen.

    7.13.5. Reading the Accelerometer
    The orientation API gets its information from a small accelerometer built into the iPhone. This tiny piece of hardware reports the raw X-Y-Z position of the device. The orientation API greatly simplifies its output into an easy-to-use list of hand-held positions, but for the more daring individuals, the accelerometer's raw data can be read directly.

    Erling Ellingsen spent a considerable amount of time disassembling the routines that talk to the accelerometer, and surprisingly found that the main application class, UIApplication, is sent frequent notifications of the accelerometer's state. To intercept these notifications, override the acceleratedInX method:

    - (void)acceleratedInX

    Please Register or Log in to view images

    float)xAxis Y

    Please Register or Log in to view images

    float)yAxis Z

    Please Register or Log in to view images

    float)zAxis {

    /* Accelerometer as X-Axis, Y-Axis, and Z-Axis */
    }



    Because the iPhone's accelerometer doesn't include a gyroscope, it can't provide information about speed, or as much detail about the state of the device as, say, a Nintendo Wii controller. It has proven useful, however, for simple applications such as bobble heads and etch-a-sketch programs, which rely on sensing when the iPhone is shaken.

    7.13.6. Further Study
    Check out the UIView-Geometry.h prototypes in the tool chain's include directory. This can be found in /usr/local/arm-apple-darwin/include/UIKit.
  6. ricardofelix95

    ricardofelix95 Banned

    Joined:
    Mar 16, 2008
    Messages:
    2,702
    Likes Received:
    4
    WOW, thanks for the write up
  7. hobofan

    hobofan New Member

    Joined:
    Jun 1, 2008
    Messages:
    68
    Likes Received:
    0
    yeah looks really nice, I'll try that now

    Please Register or Log in to view images



    p.s.: where's the whole tutorial??
  8. Commander147

    Commander147 Member

    Joined:
    Oct 10, 2007
    Messages:
    78
    Likes Received:
    4
    Device:
    iPhone 4 (Black)
    he posted that out of a book

    iPhone Open Application Development
    by Jonathan A. Zdziarski

    That whole post was copy and pasted from that book.
    Nickll9009 thats copyright material you can't just posted it like that...
  9. hobofan

    hobofan New Member

    Joined:
    Jun 1, 2008
    Messages:
    68
    Likes Received:
    0
    i won't say anything against that^^
  10. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    nick a retard. 1. you copied that. 2. the book to begin with is bootlegged.

Share This Page