Hey guys,
This is a pure UIKit topic, nothing related to Sparrow. I mostly made apps using Starling and in AS3 we're lacking let say some video options.
I'm working on an ANE to display videos on top of AS3 https://github.com/DaVikingCode/Video-ANE. All the video code works fine. However I've issue dealing with the device orientation, Flash is giving the stage orientation (since we may have limit it via our *-app.xml and Objective-C won't know) each time there is a new one.
So I rotate the view accordingly: https://github.com/DaVikingCode/Video-ANE/blob/master/ios/VideoIosExtension/VideoIosExtension/MultipleNativeVideo.m#L61
The rotation works great but not the positionning (I know I put 0 to x, y). Also when I change video position it doesn't work well if the orientation changed https://github.com/DaVikingCode/Video-ANE/blob/master/ios/VideoIosExtension/VideoIosExtension/MultipleNativeVideo.m#L56
In fact, I'm lost between changing layer's frame or bounds. Whatever I tried, I've strange result. I'm not much familiar with Cocoa API (I mostly use Sparrow in Objective-C 😉).
Do you have any ideas how to rotate correctly the view? And keep the same coordinate system than flash, so my Flash & objective-C objects are at the same position?
A video of my issue: https://vine.co/u/1123656599722967040
The code concerned:
UIWindow *rootView = [[[UIApplication sharedApplication] delegate] window];
MultipleNativeVideo *video = [[MultipleNativeVideo alloc] initWithFrame:CGRectMake(posX, posY, width, height) andUrl:[NSString stringWithUTF8String:(char*) url] ofType:[NSString stringWithUTF8String:(char *) type]withOrientation:[NSString stringWithUTF8String:(char*) orientation]];
[rootView addSubview:video];
// In my Video class:
_player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:videoUrl]];
_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
_playerLayer.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
[self.layer addSublayer:_playerLayer];
[self changePositionX:frame.origin.x andY:frame.origin.y];
- (void) changePositionX:(double) posX andY:(double) posY {
[self.layer setFrame:CGRectMake(posX, posY, self.frame.size.width, self.frame.size.height)];
}
- (void) changeOrientation:(NSString *) orientation {
CGFloat degree = 0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.55];
if ([orientation isEqualToString:@"default"])
self.layer.bounds = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
else if ([orientation isEqualToString:@"upsideDown"]) {
degree = -180;
self.layer.bounds = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
} if ([orientation isEqualToString:@"rotatedLeft"]) {
degree = -90;
self.layer.bounds = CGRectMake(0, 0, self.frame.size.height, self.frame.size.width);
} else if ([orientation isEqualToString:@"rotatedRight"]) {
degree = 90;
self.layer.bounds = CGRectMake(0, 0, self.frame.size.height, self.frame.size.width);
}
self.layer.transform = CATransform3DMakeRotation(degree / 180 * M_PI, 0, 0, 1);
[UIView commitAnimations];
}
Do you have any ideas how to rotate correctly the view? And keep the same coordinate system than flash, so my Flash & objective-C objects are at the same position?
Thanks!