Change Interface Orientation from landScape to portrait by pressing a button [duplicate] - cocos2d-x

This question already has answers here:
How to change the device orientation programmatically in iOS 6 [duplicate]
(15 answers)
Closed 8 years ago.
I want to change Interface Orientation from landScape to portrait by pressing a button in cocos2dx v2 c++

Add a class variable
Bool isInLandsCapeOrientation;
in viewDidLoad
set this flag to
isInLandsCapeOrientation = false;
Add the following function
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (!isInLandsCapeOrientation) {
return (UIInterfaceOrientationIsPortrait(interfaceOrientation));
}else {
return (UIInterfaceOrientationIsLandscape(interfaceOrientation));
}
}
To changing orientation from portrait to landscape, let it happens on a button action
- (IBAction)changeOrientationButtonPressed:(UIButton *)sender
{
isInLandsCapeOrientation = true;
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
}

Related

Xamarin.Forms.GoogleMaps does not show street background

I'm testing googlemaps using xamarin. Android platforms is ok, but in iOS i cannot see map background. I declared a variable with my credencial in AppDelegate.cs
The test only show pin address. The problem is exclusively with the background (street or satellite)
Test on Android OK.
This object receives all information about the location
readonly Pin _pinCBC = new Pin()
{
Icon = BitmapDescriptorFactory.DefaultMarker(Color.Red),
Type = PinType.Place,
Label = "61CBC",
Address = "Washington Avenue",
Position = new Position(-3.777777, -38.488888),
ZIndex = 1
};
And this method prints the map on screen. Initialize componente and after add object and positioning the pin to center
public MapsPage()
{
InitializeComponent();
map.MyLocationEnabled = true;
map.UiSettings.MyLocationButtonEnabled = true;
_pinCBC.IsDraggable = true;
map.Pins.Add(_pinCBC);
map.SelectedPin = _pinCBC;
map.MoveToRegion(MapSpan.FromCenterAndRadius(_pinCBC.Position, Distance.FromMeters(5000)), true);
}
How could I show background map. Maybe there is any missing property to inform?
iOS Simulator

ViewNavigator display top of application

I have a s:ViewNavigator component inside of s:TabbedViewNavigatorApplication. Currently it shows up at the bottom. How can I make it display at the top of the app just below action bar? I looke though all related skins in the flex sdk but I found nothing relating to position.
P.S. this is a mobile app in Flash Builder 4.6
In s:TabbedViewNavigatorApplication component:
var nav:ViewNavigator = new ViewNavigator();
nav.label = "Newest";
nav.firstView = HomeView;
nav.firstViewData = "recent";
nav.percentWidth = 100;
nav.percentHeight = 100;
this.addElement(nav);
nav.titleContent = [];
Changes in s:TabbedViewNavigatorApplication Skin:
(Swapped if statements)
(changed y position of tabBar by 60)
if (contentGroup.includeInLayout)
{
var contentGroupHeight:Number = (_isOverlay) ? unscaledHeight : Math.max(unscaledHeight - tabBarHeight, 0);
contentGroup.setLayoutBoundsSize(unscaledWidth, contentGroupHeight);
contentGroup.setLayoutBoundsPosition(0, 0);
}
if (tabBar.includeInLayout)
{
tabBarHeight = Math.min(tabBar.getPreferredBoundsHeight(), unscaledHeight);
tabBar.setLayoutBoundsSize(unscaledWidth, tabBarHeight);
tabBar.setLayoutBoundsPosition(0, 60); //unscaledHeight - tabBarHeight
tabBarHeight = tabBar.getLayoutBoundsHeight();
// backgroundAlpha is not a declared style on ButtonBar
// TabbedViewNavigatorButtonBarSkin implements for overlay support
var backgroundAlpha:Number = (_isOverlay) ? 0.75 : 1;
tabBar.setStyle("backgroundAlpha", backgroundAlpha);
}
Changes in ViewNavigator Skin:
(took away (-) contentGroupPosition from contentGroupHeight)
(multiplied contentGroupPosition by 2 so that other elements in the app would not be below the buttonBar. Action bar and buttonBar will have to be same size for this to work properly and There is no way to access the height of the button bar itself from vieNavigator skin as far as I can tell)
if (contentGroup.includeInLayout)
{
// If the hostComponent is in overlay mode, the contentGroup extends
// the entire bounds of the navigator and the alpha for the action
// bar changes
// If this changes, also update validateEstimatedSizesOfChild
var contentGroupHeight:Number = (_isOverlay) ? unscaledHeight : Math.max(unscaledHeight - actionBarHeight, 0);
var contentGroupPosition:Number = (_isOverlay) ? 0 : actionBarHeight;
contentGroup.setLayoutBoundsSize(unscaledWidth, contentGroupHeight-contentGroupPosition);
contentGroup.setLayoutBoundsPosition(0, contentGroupPosition*2);
}

Custom annotation view in Google Maps SDK

I created an iOS application based on maps in which I thought to use Google Maps SDK for iOS instead of Mapkit, I found the documentation but it I didn’t find methods related to custom annotation view, Can anyone provide me the solution for how to create custom annotation view(info window) and how to add content(title, snippet) for it.
I don't know about y'all, but I find Google's rendered UIView info windows to be a bit restricting. Using SMCalloutView and Ryan Maxwell's example project, it's possible to present more interactive views.
This works on Google Maps SDK v1.8.1, as of 2014-June-10.
First, do some set up:
#import <SMCalloutView/SMCalloutView.h>
static const CGFloat CalloutYOffset = 10.0f;
#interface ViewController ()
#property (strong, nonatomic) SMCalloutView *calloutView;
#property (strong, nonatomic) UIView *emptyCalloutView;
#end
Initialize SMCalloutView, add a button to it, then create an empty UIView:
- (void)viewDidLoad
{
/* all your other view init, settings, etc... */
self.calloutView = [[SMCalloutView alloc] init];
self.calloutView.hidden = YES;
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self
action:#selector(calloutAccessoryButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];
self.calloutView.rightAccessoryView = button;
self.emptyCalloutView = [[UIView alloc] initWithFrame:CGRectZero];
}
We have to draw that empty UIView to satisfy the Maps SDK, but the view we will display is SMCalloutView. I also set a reuseable vertical offset for the callout view.
Add delegate methods to handle info window calls:
#pragma mark - GMSMapViewDelegate
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
CLLocationCoordinate2D anchor = marker.position;
CGPoint point = [mapView.projection pointForCoordinate:anchor];
self.calloutView.title = marker.title;
self.calloutView.calloutOffset = CGPointMake(0, -CalloutYOffset);
self.calloutView.hidden = NO;
CGRect calloutRect = CGRectZero;
calloutRect.origin = point;
calloutRect.size = CGSizeZero;
[self.calloutView presentCalloutFromRect:calloutRect
inView:mapView
constrainedToView:mapView
animated:YES];
return self.emptyCalloutView;
}
- (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position {
/* move callout with map drag */
if (pMapView.selectedMarker != nil && !self.calloutView.hidden) {
CLLocationCoordinate2D anchor = [pMapView.selectedMarker position];
CGPoint arrowPt = self.calloutView.backgroundView.arrowPoint;
CGPoint pt = [pMapView.projection pointForCoordinate:anchor];
pt.x -= arrowPt.x;
pt.y -= arrowPt.y + CalloutYOffset;
self.calloutView.frame = (CGRect) {.origin = pt, .size = self.calloutView.frame.size };
} else {
self.calloutView.hidden = YES;
}
}
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
self.calloutView.hidden = YES;
}
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
/* don't move map camera to center marker on tap */
mapView.selectedMarker = marker;
return YES;
}
Handle touches on the callout button, here using an alert view with marker title and snippet:
- (void)calloutAccessoryButtonTapped:(id)sender {
if (mapView_.selectedMarker) {
GMSMarker *marker = mapView_.selectedMarker;
//NSDictionary *userData = marker.userData;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:marker.title
message:marker.snippet
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
Obviously, make sure your ViewController(.h) listens to GMSMapViewDelegate:
#interface ViewController : UIViewController <GMSMapViewDelegate>
And that should basically work. For a complete xcode project, see the aforementioned example from Ryan Maxwell.
If you check GMSMapView.h within GoogleMaps.Framework, you can see the below method which should let you add a custom infowindow for a marker, instead of using standard title and snippet alone:
NOTE you (op) say annotationView=infoWindow
BUT NORMAL: annotationView = marker itself and calloutView = infoWindow
/**
* Called when a marker is about to become selected, and provides an optional
* custom info window to use for that marker if this method returns a UIView.
* If you change this view after this method is called, those changes will not
* necessarily be reflected in the rendered version.
*
* The returned UIView must not have bounds greater than 500 points on either
* dimension. As there is only one info window shown at any time, the returned
* view may be reused between other info windows.
*
* #return The custom info window for the specified marker, or nil for default
*/
- (UIView *)mapView:(GMSMapView *)mapView
markerInfoWindow:(id<GMSMarker>)marker;

How can I detect image orientation (portrait vs. landscape) after its loaded then rotate stage accordingly?

Im using flash builder 4.5 and AS3 to load images dynamicallly from a live JSON data source. its loading and working fine and responding to my swipe gestures (left swipe to go BACK and right swipe to advance to next image)...
I'd like to add some actionscript to detect the orientation of the picture after its loaded successfully then if its a vertically oriented photo, turn the stage 90 degrees (and set some type of flag to remember that its in that 'rotated state'.
how can I achieve this?
if (myPic && myPic.width > myPic.height)
{
// this picture is horizontal, so leave stage in normal landscape aspect ratio
} else {
// something here to take the stage and rotate it 90 degrees
}
You can use the width:height ratio to work out whether the shape of the image is portrait or landscape. I am not confident that you want to rotate the Stage but rather the image itself.
Here is a class I've written up that can help:
public class PhotoHolder extends Sprite
{
public static const Landscape:int = 0;
public static const Portrait:int = 1;
private var _bitmap:Bitmap;
private var _orientation:int = 0;
public function PhotoHolder(bitmap:Bitmap)
{
_bitmap = bitmap;
_bitmap.x = -(_bitmap.width / 2);
_bitmap.y = -(_bitmap.height / 2);
if(bitmap.width >= bitmap.height) _orientation = Landscape;
else
{
rotation = 90;
_orientation = Portrait;
}
addChild(_bitmap);
}
public function get orientation():int
{
return _orientation;
}
}
This will manage the rotation for you and you'll be able to determine if the image was originally a Landscape or Portrait orientation via .orientation.

Weird thing occurred when porting isometric tiled map from cocos2d for iPhone to cocos2dx

I am trying to convert some Cocos2d-iphone code to Cocos2d-x code but some weird things happened with isometric tiled map.
The ground becomes totally dark.Please help me.
In Objective-C:
-(id) init { if ((self = [super init])) { CCTMXTiledMap* tileMap = [CCTMXTiledMap tiledMapWithTMXFile:#"isometric-with-border.tmx"];
[self addChild:tileMap z:-1 tag:TileMapNode];
CCTMXLayer* layer = [tileMap layerNamed:#"Collisions"]; layer.visible
= NO;
// Use a negative offset to set the tilemap's start position
tileMap.position = CGPointMake(-500, -500); …. } }
In C++:
bool TiledMap::init() { if ( !CCLayer::init() ) { return false; }
CCTMXTiledMap *tileMap =
CCTMXTiledMap::create("isometric-with-border.tmx");
this->addChild(tileMap,1,TileMapNode);
CCTMXLayer* layer = tileMap->layerNamed("Collisions");
layer->setVisible(false);
// Use a negative offset to set the tilemap's start position
tileMap->setPosition(-500, -500); …. }