Closed dabitdev closed 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];
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°
I'll add this change rigth away, thanks for the contribution.
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];
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;
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
Check my fork and this commit : https://github.com/sylverb/toast-notifications-ios/commit/6e1cc77a9cba98f9587fd667c549c6ab356bede7 it's already handling most cases ;)
Sweet!
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!