GauravWahi / toast-notifications-ios

Automatically exported from code.google.com/p/toast-notifications-ios
0 stars 0 forks source link

Toast Notification doen't rotate with interface #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.   Turn iPhone/iPad on side and trigger a Toast

What is the expected output? What do you see instead?
Notification should be aligned with the interface at the moment all Toasts are 
displayed as portrait only leading to incorrect alignment

What version of the product are you using? On what operating system?

Using latest Source.

Please provide any additional information below.

I have edited my version of the code but can't submit the changes - if you want 
to add me a collaborator I'll push my changes to the project to fix this 
problem.

Original issue reported on code.google.com by steven.j...@gmail.com on 22 Mar 2011 at 11:03

GoogleCodeExporter commented 9 years ago
Thank you for the interest.
Please submit a  patch and i'll commit the code to the project.

Original comment by exilire2...@gmail.com on 8 May 2011 at 3:09

GoogleCodeExporter commented 9 years ago
Hi! I'm also interested in the patch making landscape-mode work. Any news on 
this?

Original comment by torben.n...@gmail.com on 12 May 2011 at 8:37

GoogleCodeExporter commented 9 years ago
At the moment I'm at GoogleIO in San Fransisco so i will submit the
fix when i get back home on Monday. Hopefully it will be added into
the branch at some point

Steve

Original comment by steven.j...@gmail.com on 12 May 2011 at 4:54

GoogleCodeExporter commented 9 years ago
has this been fixed?

Original comment by aditya15...@gmail.com on 25 May 2011 at 6:53

GoogleCodeExporter commented 9 years ago
I have the code on my machine - Can you let me know where you want me to submit 
the patch to as I can't seem to check it in to the project as I'm not a 
collaborator.  Potentially I could fork the project with the changes in it. 
It's up to you what I do

Steve

Original comment by steven.j...@gmail.com on 25 May 2011 at 7:26

GoogleCodeExporter commented 9 years ago
I have actualy fixed this on my own by doing the following:

 UIView *parentView = nil;  
    UIWindow* window = [UIApplication sharedApplication].keyWindow;
    if (!window) {
        window = [[UIApplication sharedApplication].windows objectAtIndex:0];           
    }       
    UIView *firstSubview = [[window subviews] objectAtIndex:0];
    parentView = [[firstSubview subviews] objectAtIndex:0];

and add the subview to the parentView instead of window, this fixes it to 
anyone who needs it

Original comment by aditya15...@gmail.com on 25 May 2011 at 7:58

GoogleCodeExporter commented 9 years ago
I fixed the orientation by looking at the status bar and transforming
the overlay to the correct orientation.

Add the following to -(void) show

//Rotate Based on Orientation
    UIInterfaceOrientation currentOrient= [UIApplication
sharedApplication].statusBarOrientation;

    if((currentOrient == UIDeviceOrientationLandscapeRight)){
        //Home Button to Right
        v.transform = CGAffineTransformRotate(v.transform, (M_PI/2) * -1);
    }else if((currentOrient == UIDeviceOrientationLandscapeLeft)){
        //Home Button to Left
        v.transform = CGAffineTransformRotate(v.transform, (M_PI/2));
    }

Hope this helps anyone

Steve

On Wed, May 25, 2011 at 8:59 PM,
<toast-notifications-ios@googlecode.com> wrote:

Original comment by steven.j...@gmail.com on 1 Jun 2011 at 2:31

GoogleCodeExporter commented 9 years ago
I made a slight update to your code --  since no one seems to have committed to 
the project (or has had difficulty doing so). This accounts for upside down 
orientation. 

(FYI: if you use the gravity parameter you will need to adjust the offset of 
the notification such that it doesnt rub against the edge of the screen)

{{{    
    //Edit from Project website.
    //Rotate Based on Orientation
    UIInterfaceOrientation currentOrientation= [UIApplication
                                           sharedApplication].statusBarOrientation;

    if(currentOrientation == UIInterfaceOrientationPortraitUpsideDown){
        v.transform = CGAffineTransformRotate(v.transform, (M_PI) * -1);
    }
    else if(currentOrientation == UIInterfaceOrientationPortrait) {
     //Be Normal // No Change
    }
    else if(currentOrientation == UIDeviceOrientationLandscapeRight){
        //Home Button to Right
        v.transform = CGAffineTransformRotate(v.transform, (M_PI/2) * -1);
    }
    else if(currentOrientation == UIDeviceOrientationLandscapeLeft){
        //Home Button to Left
        v.transform = CGAffineTransformRotate(v.transform, (M_PI/2));
    }
}}}

Original comment by cde...@gmail.com on 18 Aug 2011 at 12:04

GoogleCodeExporter commented 9 years ago
Here is a fully updated version of the code. That one fixes the offsets for 
custom gravities (though i haven't tested the positionning for 
PortraitUpsideDown).

UIWindow *window = [[[UIApplication sharedApplication] windows] 
objectAtIndex:0];

    UIInterfaceOrientation currentOrientation= [UIApplication
                                                sharedApplication].statusBarOrientation;

    CGPoint point = CGPointMake(window.frame.size.width/2, window.frame.size.height/2);

    if (theSettings.gravity == iToastGravityTop) {

        if (currentOrientation == UIInterfaceOrientationPortrait)
            point = CGPointMake(window.frame.size.width / 2, 45);
        else if (currentOrientation == UIInterfaceOrientationLandscapeLeft)
            point = CGPointMake(45, window.frame.size.height / 2);
        else if (currentOrientation == UIInterfaceOrientationLandscapeRight)
            point = CGPointMake(window.frame.size.width - 45, window.frame.size.height / 2);    
        else
            point = CGPointMake(window.frame.size.width / 2, window.frame.size.height - 45);        
    }else if (theSettings.gravity == iToastGravityBottom) {

        if (currentOrientation == UIInterfaceOrientationPortrait)
            point = CGPointMake(window.frame.size.width / 2, window.frame.size.height - 45);
        else if (currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
            point = CGPointMake(window.frame.size.width / 2, 45);
        else if (currentOrientation == UIInterfaceOrientationLandscapeLeft)
            point = CGPointMake(window.frame.size.width - 45, window.frame.size.height / 2);
        else if (currentOrientation == UIInterfaceOrientationLandscapeRight)
            point = CGPointMake(45, window.frame.size.height / 2);
    }else if (theSettings.gravity == iToastGravityCenter) {
        point = CGPointMake(window.frame.size.width/2, window.frame.size.height/2);
    }else{
        point = theSettings.postition;
    }

    point = CGPointMake(point.x + offsetLeft, point.y + offsetTop);
    v.center = point;

    NSTimer *timer1 = [NSTimer timerWithTimeInterval:((float)theSettings.duration)/1000 
                                             target:self selector:@selector(hideToast:) 
                                           userInfo:nil repeats:NO];
    [[NSRunLoop mainRunLoop] addTimer:timer1 forMode:NSDefaultRunLoopMode];

    //Edit from Project website.
    //Rotate Based on Orientation

    if(currentOrientation == UIInterfaceOrientationPortraitUpsideDown){
        v.transform = CGAffineTransformRotate(v.transform, (M_PI) * -1);
    }
    else if(currentOrientation == UIInterfaceOrientationPortrait) {
        //Be Normal // No Change
    }
    else if(currentOrientation == UIDeviceOrientationLandscapeRight){
        //Home Button to Right
        v.transform = CGAffineTransformRotate(v.transform, (M_PI/2) * -1);
    }
    else if(currentOrientation == UIDeviceOrientationLandscapeLeft){
        //Home Button to Left
        v.transform = CGAffineTransformRotate(v.transform, (M_PI/2));
    }

    [window addSubview:v];

Original comment by ded...@gmail.com on 5 Jan 2012 at 2:55