ecstasy2 / toast-notifications-ios

We at Guru software really love toast notifications available on android OS, so we've built a similar feature for the IOS enabled devices.
MIT License
325 stars 106 forks source link

iToast position in landscape mode #1

Closed dabitdev closed 12 years ago

dabitdev commented 12 years ago

for example, if someone set the iToast in Bottom mode, if the iphone is in landscape the toast is showed in the left or right side.

A possible solution is to handle the orientation but there is the other problem with the alignment of the text.

Dave!

julianfe commented 12 years ago

Very quick answer, needs some proper code to detect orientation but in the meantime

v.transform = CGAffineTransformMakeRotation(4.712388975); //rotation in radians 6.2831853 4.712388975 3.14159265 1.570796325

[window addSubview:v];

julianfe commented 12 years ago

I've think I may have added a fork with the code to do this, but I've never Git's before so excuse me if I've bodged it.

Here's the code just in case, add before [window addSubview:v];

if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
    v.transform = CGAffineTransformMakeRotation(1.570796325); //rotation in radians
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
    v.transform = CGAffineTransformMakeRotation(4.712388975);
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
    v.transform = CGAffineTransformMakeRotation(3.14159265);
}
// Normal is 6.2831853 ie 360°
ecstasy2 commented 12 years ago

I'll add this change rigth away, thanks for the contribution.

julianfe commented 12 years ago

I had to update my code, here's working code from iPad 1 and 2

// I could add a listener to rotate during rotation
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];  

NSLog(@"orientation: %d", [[UIDevice currentDevice] orientation]);

if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
    v.transform = CGAffineTransformMakeRotation(1.570796325); //rotation in radians
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
    v.transform = CGAffineTransformMakeRotation(4.712388975);
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
    v.transform = CGAffineTransformMakeRotation(3.14159265);
}
// Normal is 6.2831853 ie 360°

if ([[UIDevice currentDevice] orientation] == 3) {
    v.transform = CGAffineTransformMakeRotation(1.570796325); //rotation in radians
} else if ([[UIDevice currentDevice] orientation] == 5) {
    v.transform = CGAffineTransformMakeRotation(4.712388975);
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
    v.transform = CGAffineTransformMakeRotation(3.14159265);
}

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
sylverb commented 12 years ago

julianfe, your previous commit was not working for me with iToastGravityBottom (maybe it's working for centered nitifications ?), I had to rewrite something more complex to handle orientation ! Other issues in your code : [[UIDevice currentDevice] orientation] is giving the current device orientation with type UIDeviceOrientation (portrait/portrait upside down/landscape left/ landscape right but also unknown/face up/face down which are definitely not something usefull ...): typedef enum { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, UIDeviceOrientationPortraitUpsideDown, UIDeviceOrientationLandscapeLeft, UIDeviceOrientationLandscapeRight, UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown } UIDeviceOrientation;

Moreover, if you start the application in lanscape mode, this may return an incorrect orientation ... What we need is the interface orientation, this is usually retrieved using [[UIApplication sharedApplication] statusBarOrientation] which returns a UIInterfaceOrientation type : typedef enum { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft } UIInterfaceOrientation;

julianfe commented 12 years ago

Yes I was probably a bit pre-emptive in uploading my version - it was written for an app specifically and covered my needs.

I'm actually rewriting it to also handle rotation whilst displaying

sylverb commented 12 years ago

Check my fork and this commit : https://github.com/sylverb/toast-notifications-ios/commit/6e1cc77a9cba98f9587fd667c549c6ab356bede7 it's already handling most cases ;)

julianfe commented 12 years ago

Sweet!