CCScrollView scroll and touch events never firing - ios

I can't find any helpful tutorials or explanation on how to use a CCScrollView. I have a grid-layout of sprites and labels (listing achievements for an iOS game). There are more than can fit on the screen so I want the user to be able to scroll.
To scroll, the user would swipe/pan upwards, to reveal the sprites etc which are lower.
I've found a few code samples and they seem to indicate you just need to add your content node to the scroll node and it will take care of the rest.
It doesn't seem to work. There's no scroll, and the pan/touch events on the scroll layer never seem to fire. The close button I have at the same child (sibling to the scroll view) no longer works as well.
I'm not using SpriteBuilder.
// Node to hold all sprites/labels
scrollContents = [CCNode node];
// I add a bunch of sprites/labels in a grid view
for( NSString *key in badgeKeys ){
// logic to load the sprite would be here
CCSprite *badge = [CCSprite spriteWithSpriteFrame:frame];
badge.positionType = CCPositionTypeNormalized;
badge.position = ccp(xPos,yPos);
[scrollContents addChild:badge];
// some logic to increment x/y position logic, for grid layout
}
// Scroll view
scrollView = [[CCScrollView alloc] initWithContentNode:scrollContents];
scrollView.horizontalScrollEnabled = NO;
scrollView.verticalScrollEnabled = YES;
[scrollView setBounces:NO];
// My sprites never even show unless I manually set this
scrollContents.contentSize = CGSizeMake(self.contentSize.width,960);
NSLog(#"scrollContents contentsize: %f %f", scrollContents.contentSize.width,scrollContents.contentSize.height);
[self addChild:scrollView];

ok, here is a working example (i deconstructed part of my code to give you a fully working code sample) of a scrolling menu with 'live' buttons inside. I just tested this 'deconstruction' , it works
- (void) scrollingMenuWithCharmsTest {
// setup something to scroll
GameInventory *gi = [GameInventory sharedGameInventory];
while (gi.armorCharms.count < 20) {
[gi addArmorCharm:[ArmorCharm createRandomArmorCharm]];
}
CCNode *contentNode = [self charmsContentNodeFor:gi.armorCharms
showEquiped:NO
spacingBetweenMenuItems:8
target:self
selector:#selector(onArmorCharmSelected:)];
// setup a clipping node to crop out the CCScrollingMenu
CCNodeColor *ccn = [CCNodeColor nodeWithColor:[CCColor blackColor] width:180 height:200];
ccn.anchorPoint = ccp(0, 0);
CCClippingNode *cn = [CCClippingNode clippingNodeWithStencil:ccn];
cn.alphaThreshold = 0.05f;
[self addChild:cn];
cn.inverted = NO;
cn.positionInPointsV = ccp(50, 50);
cn.anchorPoint = ccp(0, 0);
cn.contentSizeInPoints = CGSizeMake(180, 200);
// setup scrolling menu
CCScrollView * bsm = [[CCScrollView alloc] initWithContentNode:contentNode];
bsm.contentSize=CGSizeMake(180,200);
[cn addChild:bsm];
bsm.position = ccp(0, 0);
bsm.bounces = YES;
bsm.pagingEnabled = NO;
bsm.verticalScrollEnabled = YES;
bsm.horizontalScrollEnabled = NO;
bsm.contentSizeInPoints = CGSizeMake(180, 200); // inPoints only after the node has a parent
for (CharmAbstractBoxMenuItem *lmi in bsm.contentNode.children) {
TRACE(#"item %# is at %#", lmi.item.description, NSStringFromCGPoint(lmi.positionInPointsV));
}
TRACE(#"number of pages : %i", bsm.numVerticalPages);
}
- (CCNode *)charmsContentNodeFor:(NSDictionary *)keyedItems
showEquiped:(BOOL)isShowEquiped
spacingBetweenMenuItems:(float)inSpacing
target:(id)inTarget
selector:(SEL)inSelector {
NSSortDescriptor *sortOrder = [NSSortDescriptor sortDescriptorWithKey:#"self" ascending:YES];
NSArray *sortedKeys = [[keyedItems allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortOrder]];
float initialY = 0;
float currentY = initialY;
NSUInteger itemNumber = 0;
CGFloat width = 0;
CGFloat height = 0;
CCNode *contentNode = [CCNode node];
for (NSUInteger loopi = 0; loopi < [sortedKeys count]; loopi++) {
NSString *key = [sortedKeys objectAtIndex:loopi];
CharmAbstract *ci = [keyedItems objectForKey:key];
if (ci) {
CharmAbstractBoxMenuItem *cmi = [CharmAbstractBoxMenuItem itemBoxFor:ci
target:inTarget
selector:inSelector
];
cmi.toolTip = ci.toolTip;
cmi.position = ccp(deviceOffset(0), currentY);
cmi.key = key;
[contentNode addChild:cmi z:0 name:[NSString stringWithFormat:#"%li", (long) itemNumber]];
currentY += cmi.contentSizeInPoints.height + inSpacing;
itemNumber++;
if (cmi.contentSize.width > width) width = cmi.contentSize.width;
height += cmi.contentSize.height;
if (loopi < sortedKeys.count - 1) height += inSpacing;
}
else {
MPLOG(#"*** Key [%#] yielded no items.", key);
}
}
contentNode.contentSizeType = CCSizeTypePoints;
contentNode.contentSize = CGSizeMake(width, height);
return contentNode;
}
some notes :
i gave you my 'build content node' routine so you know the ins and outs of positions and sizes.
my charmBoxMenuItemss derive from 'CCButton' and are hot ... In the full version of this code snippet, i extended CCScrollView to prevent the buttons from being 'hot' outside the crop area (although they are cropped out from view, they are still 'visible' by default, and could respond when a random tap occurs above or below the crop area).
For clipping node with stencil, you need to add this in your setupCocos2dWithOptions line:
CCSetupDepthFormat : [NSNumber numberWithUnsignedInt:GL_DEPTH24_STENCIL8_OES]

Related

Show multiple crosshair target circles on Shinobicharts with same X position ( iOS )

I have a chart with 3 SChartLineSeries. I would like to show 3 simultaneous target points (from the crosshair that corresponds to his serie) at the same time.
Like I have on this picture with dataPoints, but I would like have it on the same X position with Crosshairs.
How can I achieve that? I tried to recognize the 'long press' event in the delegate method, but I didn't figure out how to do it.
With crosshairs, I only have this:
EDIT:
Ive tried:
- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
{
for (SChartLineSeries *serie in chart.series) {
for (SChartDataPoint *dp in serie.dataSeries.dataPoints){
if (dp.xValue == dataPoint.xValue){
dp.selected = YES;
serie.crosshairEnabled = YES;
serie.style.selectedPointStyle.color = [UIColor blackColor];
serie.style.selectedPointStyle.radius = [NSNumber numberWithInt:8];
serie.style.selectedPointStyle.showPoints = YES;
}
}
}
}
And subclassing the object 'SChartCrosshair' I recognize the long press event on 'crosshairChartGotLongPressAt'.
I already managed it, with the help of ShinobiControls team support.
On the 'SChartCrosshair' I subclassed, I had to loop over the points that matched with the 'Crosshair' X position touched, and adding the ones that mathed to an array for using them in 'drawCrosshairLines'. For that, I used, the pixel version of the point, through a method that understands the SChartAxis object: 'pixelValueForDataValue'.
I draw a vertical line on the chart as well.
#implementation CustomCrossHair
-(void)drawCrosshairLines
{
CGContextRef context = UIGraphicsGetCurrentContext();
SChartDataPoint *firstDataPixelPoint = arrayPixelPoints[0];
double xFirst = [firstDataPixelPoint.xValue doubleValue];
CGContextMoveToPoint(context,xFirst, 0.f);
CGContextAddLineToPoint(context,xFirst, self.chart.canvas.glView.frame.size.height);
for (SChartDataPoint *dataPixelPoint in arrayPixelPoints){
double yVal = [dataPixelPoint.yValue doubleValue];
double xVal = [dataPixelPoint.xValue doubleValue];
CGRect rectangle = CGRectMake(xVal,yVal, 7, 7);
CGContextAddEllipseInRect(context, rectangle);
}
CGContextStrokePath(context);
}
-(void)moveToPosition:(SChartPoint)coords andDisplayDataPoint:(SChartPoint)dataPoint fromSeries:(SChartCartesianSeries *)series andSeriesDataPoint:(id<SChartData>)dataseriesPoint
{
[super moveToPosition:coords andDisplayDataPoint:dataPoint fromSeries:series andSeriesDataPoint:dataseriesPoint];
arrayPixelPoints = [NSMutableArray array];
SChartDataPoint *dataSPoint = dataseriesPoint;
int i = 0;
for (SChartLineSeries *serie in self.chart.series){
i++;
for (SChartDataPoint *dp in serie.dataSeries.dataPoints){
if ([dp.xValue doubleValue] == [dataSPoint.xValue doubleValue]){
float yPixel = [self.chart.yAxis pixelValueForDataValue:dp.yValue];
float xPixel = [self.chart.xAxis pixelValueForDataValue:dp.xValue];
SChartDataPoint *dataPointPixel = [[SChartDataPoint alloc] init];
dataPointPixel.xValue = [NSNumber numberWithFloat:xPixel];
dataPointPixel.yValue = [NSNumber numberWithFloat:yPixel];
[arrayPixelPoints addObject:dataPointPixel];
}
}
}
if (i == self.chart.series.count) [self drawCrosshairLines];
}

Using CCScrollView in Cocos2d V3

I'm wondering if anyone can help me with this. I want to add 4 CCScrollViews, that will scroll horizontally, on a CCNode. The CCNode, positioned and held on the device in portrait mode, will fill the entire screen with a normalized contentSize set to cover the entire screen.
So in essence the scroll views will pile on top of each other with the 4th being at the bottom of the screen and the 1st being at the top. Now, I have managed to add the 4 CCScrollViews but only one responds to touches. The others are flat an unmovable. It's almost as though the last CCScrollView added to the node is overlaying the other three and it is the only thing responding to touch requests. All 4 CCScrollViews have their delegate property set to self.
I'm someone coming at Cocos2d with a fair bit of UIKit experience. So, i'm trying to apply my UIScrollView mode of thinking to all of this. Having had a good Google about and coming up with little, I'm wondering if SO can help. I've even been considering winding UIScrollView into Cocos2d.
I guess my main issues here are two-fold. One, I have an issue with touch response. Two, I have an issue with the paging aspect and control of content-size. Via trial and error, I'm sort of getting along but if someone could perhaps write up a bit of a best-practive guide to CCScrollView implementation, specifically where one does not set the contentSize of the CCNode or CCspriteFrame that's added to larger contentView does not fill the entire width of the screen.
Thanks in advance.
#import "CCToolKit.h"
#import "GameShip.h"
typedef enum ShipPart
{
ShipPartHead,
ShipPartBody,
ShipPartWings,
ShipPartBoosters
} ShipPart;
#implementation GameShip
-(instancetype)init {
if (self = [super init]) {
[self addBackground];
[self addScrollTo:ShipPartHead forQtyOfParts:3];
[self addScrollTo:ShipPartBody forQtyOfParts:4];
[self addScrollTo:ShipPartWings forQtyOfParts:3];
[self addScrollTo:ShipPartBoosters forQtyOfParts:3];
}
return self;
}
-(void)addBackground {
CCSprite *bg = [CCSprite spriteWithImageNamed:kGameMainBackGround];
bg.positionType = CCPositionTypeNormalized;
bg.position = ccp(0.5f,0.5f);
[self addChild:bg];
}
-(void)addScrollTo:(ShipPart)shipPart forQtyOfParts:(int)partQty {
NSString *imageFileNameSegment;
switch (shipPart) {
case ShipPartHead:
imageFileNameSegment = #"head";
break;
case ShipPartBody:
imageFileNameSegment = #"body";
break;
case ShipPartWings:
imageFileNameSegment = #"wings";
break;
case ShipPartBoosters:
imageFileNameSegment = #"boosters";
break;
default:
break;
}
CCNode *scrollViewContents = [CCNode node];
scrollViewContents.contentSizeType = CCSizeTypeNormalized;
scrollViewContents.contentSize = CGSizeMake(partQty * 0.65, 0.25f);
NSLog(#"scrollView,height %f", scrollViewContents.boundingBox.size.height);
for (int i = 1; i <= partQty; i++) {
NSString *imageFileName = [NSString stringWithFormat:#"%#%d.png", imageFileNameSegment, i];
CCSprite *shipPartSprite = [CCSprite spriteWithImageNamed:imageFileName];
shipPartSprite.positionType = CCPositionTypeNormalized;
shipPartSprite.position = ccp((i + 0.5f) / partQty, 0.5f);
[scrollViewContents addChild:shipPartSprite];
}
CCScrollView *scrollView = [[CCScrollView alloc] initWithContentNode:scrollViewContents];
scrollView.pagingEnabled = YES;
scrollView.horizontalScrollEnabled = YES;
scrollView.verticalScrollEnabled = NO;
scrollView.color = [CCColor redColor];
scrollView.contentSize = CGSizeMake(0.5f, 0.25f);
scrollView.positionType = CCPositionTypeNormalized;
scrollView.position = ccp(-1.0f, ((shipPart * 0.25f) -0.1f));
scrollView.delegate = self;
//scrollView.description = [NSString stringWithFormat:#"%d", shipPart];
[self addChild:scrollView];
//[scrollView setHorizontalPage:1];
}

How to spawn CCSprites in random heights like flappy bird

In the iOS game flappy bird, there are pipes that generate after a certain distance and they generate at random heights
I am also trying to make flappy bird pipes (I called it a tree branch in my code instead of pipe). Except the pipes are moving vertically instead of horizontally because it is a vertical scrolling game (it scrolls like the game doodle jump)
This is a drawing of what I want it to be: https://docs.google.com/drawings/d/18bxsVsNOlScCvgi1mwuzD2At7R6xKM3QCh6BfAVMuMo/edit?usp=sharing
(The horizontal lines are the branches)
So this is what I have tried to do so far to make the vertical branches (or pipes)...
in my .h
CCSprite *branch;
NSMutableArray *_branches;
CCSprite *obstacle;
CCNode *previousBranch;
CGFloat previousBranchYPosition;
in my .m
#implementation HelloWorldLayer
static const CGFloat firstBranchPosition = 426.f;
static const CGFloat distanceBetweenBranches = 140.f;
#define ARC4RANDOM_MAX 0x100000000
static const CGFloat minimumXPositionRightBranch = 280.f;
static const CGFloat maximumXPositionLeftBranch = 50.f;
static const CGFloat pipeDistance = 100.f;
static const CGFloat maximumXPositionRightBranch = maximumXPositionLeftBranch - pipeDistance;
setBranchInitialPosition method
/* This is where I am setting the initial position of the branches.
So I am specifying the position of the first branch and the other branches after it so it gets placed every time a certain distance is passed. I have a left branch and a right branch*/
-(void) setBranchInitialPosition {
CGFloat random = ((double)arc4random() / ARC4RANDOM_MAX);
CGFloat range = maximumXPositionRightBranch - minimumXPositionRightBranch;
_rightBranch.position = ccp(minimumXPositionRightBranch + (random * range), _rightBranch.position.y);
_leftBranch.position = ccp(_rightBranch.position.x + pipeDistance, _leftBranch.position.y);
}
spawnNewBranches method
// This is how I want the branches to spawn and I want to add them to an array full of branches
- (void)spawnNewBranches {
previousBranch = [_branches lastObject];
previousBranchYPosition = previousBranch.position.y;
if (!previousBranch) {
// this is the first obstacle
previousBranchYPosition = firstBranchPosition;
}
_rightBranch = [CCSprite spriteWithFile:#"branch.png"];
_leftBranch = [CCSprite spriteWithFile:#"branch.png"];
[_leftBranch addChild:_rightBranch];
[self setBranchInitialPosition];
obstacle = [CCSprite node];
[obstacle addChild:_leftBranch];
obstacle.position = ccp(160, previousBranchYPosition + distanceBetweenBranches);
[self addChild:obstacle];
[_branches addObject:obstacle];
}
scroll method
-(void) scroll:(ccTime)dt
{
// moves the bg
background.position = ccp(screenCenter.x, background.position.y + [[NSUserDefaults standardUserDefaults] integerForKey:#"scrollSpeed"]*dt);
bg2.position = ccp(screenCenter.x, background.position.y-background.contentSize.height);
// it adds the new bg's to the screen before the old bg's move off the screen
if (background.position.y >= screenSize.height*1.5)
{
background.position = ccp(screenCenter.x, (screenCenter.y)-(background.size.height/2));
} else if (bg2.position.y >= screenSize.height*1.5) {
bg2.position = ccp(screenCenter.x, (screenCenter.y)-(bg2.size.height/2));
}
// This is where I want them to appear every certain distance and also move with the brackground
obstacle.position = ccp(obstacle.position.x, obstacle.position.y*[[NSUserDefaults standardUserDefaults] integerForKey:#"scrollSpeed"]*dt);
NSMutableArray *offScreenObstacles = nil;
if (obstacle.position.y >= screenSize.height*1.5) {
[offScreenObstacles addObject:obstacle];
}
for (CCNode *obstacleToRemove in offScreenObstacles) {
[obstacleToRemove removeFromParent];
[_branches removeObject:obstacleToRemove];
// for each removed obstacle, add a new one
[self spawnNewBranches];
}
}
Right now, the branches are appearing, but they stay in the bottom left corner and they dont move or spawn at all. I want to make them move with the background and spawn after a certain distance while also being generated in random heights. I provided you with all my code, do you know how I can make this work? Thanks in advance!
You may want to try placement of the pipes based on a trigonometric curve like sine or cosine (https://en.wikipedia.org/wiki/Trigonometric_functions). It seems like you are placing the pipes within a fairly define random range though if you change this range to an offset from the plot of the trigonometric curve it would take into account the ability of the player to transition between the open gaps better. At least that's my feel. I think the code would be easier to follow as well as I'm a bit confused going through it. You can also easily vary the difficulty of the curve by changing the parameters such as increasing the amplitude or frequency.
I created a copy of Flappy Bird just for fun. I used this code to create the pipes:
-(void)createPipes{
//Create Random
int from = 65;
int max = [[UIScreen mainScreen] bounds].size.height - 124;
int delta = max - from - dy;
int y = from + arc4random() % (delta - from);
//Pipe Bottom
UIImageView *pipeBottom = [[UIImageView alloc] init];
[pipeBottom setContentMode:UIViewContentModeTop];
[pipeBottom setImage:[UIImage imageNamed:#"pipeBottom"]];
[pipeBottom setFrame:CGRectMake(320, y+dy, 60, max - y - dy)];
[pipeBottom setClipsToBounds:YES];
//Pipe Top
UIImageView *pipeTop = [[UIImageView alloc] init];
[pipeTop setFrame:CGRectMake(320, 0, 60, y)];
[pipeTop setContentMode:UIViewContentModeBottom];
[pipeTop setImage:[UIImage imageNamed:#"pipeTop"]];
[self.view insertSubview:pipeTop atIndex:1];
[self.view insertSubview:pipeBottom atIndex:1];
if (!self.pipes)
self.pipes = [[NSMutableArray alloc] init];
[self.pipes addObject:pipeBottom];
[self.pipes addObject:pipeTop];
}
and to move them:
-(void)moveArray:(NSMutableArray *)array{
float ds = dv * dt;
NSMutableArray *trash = [NSMutableArray array];
for (UIImageView *obj in array) {
CGRect frame = obj.frame;
frame.origin.x -= ds;
if (frame.origin.x < -frame.size.width) {
[obj removeFromSuperview];
[trash addObject:obj];
}else{
obj.frame = frame;
}
}
[array removeObjectsInArray:trash];
}
-(void)movePipes{
[self moveArray:self.pipes];
}
I call this function every 0.01 seconds, to run the game:
-(void)runGame{
_time += dt;
if (_time >= 180.0/dv) {
_time = 0;
[self createPipes];
}
[self movePipes];
[self moveEnemies];
[self moveYoshi];
[self moveBar];
[self verifyScore];
[self verifyCollision];
[self verifyState];
}
I defined dt = 0.01 and dv = 110.
You can see my parody in youtube: (http://www.youtube.com/watch?v=tTcYdpSIKJg)
I hope this help you.
Best, Rafael Castro.

'CALayer position contains NaN: [nan nan]' when working with Bouncing Ball Array in C4

So I'm trying to just recreate a bouncing ball app using xcode and C4. What I'm trying to do right now is re-create some of the examples in Dan Shiffmans Nature of Code book in C4.
So far I've managed to create my own class of "Mover" objects that bounce around the screen. That's all working great. The next step was to start "applying some forces" to the movers and play around with that.
I seem to be getting an exception thats crashing the program now that I've added methods to apply force. I put on exception breakpoints and this line in C4Control.m is where it stops:
if(_animationDuration == 0.0f) super.center = center;
Looking into this more, I notice that neither super.center or center properties have a value assigned to them (both of NaN). I'm not sure what's causing this? This seemed to start once I decided to set each Movers initial velocity/accel to 0 and only assign "fores" (C4Vectors for wind and gravity) to create motion in these objects. When I comment out the 2 lines that apply each force, the problem goes away.
This is the implementation of my mover class:
//Init Method
- (id)initWithPoint:(CGPoint)point andCanvasController:(C4CanvasController *)canvasController {
self = [super init];
if (self) {
canvasFrame = CGPointMake(canvasController.canvas.width,
canvasController.canvas.height);
diam = [C4Math randomInt:70];
mass = diam * 0.5f;
CGRect ellipseFrame = CGRectMake(0, 0, diam, diam);
[self ellipse:ellipseFrame];
self.lineWidth = 0.0f;
self.fillColor = [UIColor colorWithRed:[C4Math randomInt:60]/60
green:[C4Math randomInt:100]/100.0f
blue:0.9f
alpha:0.3f];
int foo = arc4random() % (int)([canvasController.canvas height]);
int bar = arc4random() % (int)([canvasController.canvas width]);
self.location = [C4Vector vectorWithX:foo
Y:bar
Z:0.0f];
self.origin = self.location.CGPoint;
self.accel = [C4Vector vectorWithX:0.00f Y:0.0f Z:0.0f];
self.vel = [C4Vector vectorWithX:0.00f Y:0.0f Z:0.0f];
}
return self;
}
//Method to calculate updated mover position
-(void)update{
[self.vel add:self.accel];
[self.location add:self.vel];
self.origin = self.location.CGPoint;
[self.accel multiplyScalar:0];
[self checkBounds];
}
//Checking if mover has reached edge of screen
-(void)checkBounds{
if (self.origin.x > canvasFrame.x - diam){
self.location.x = canvasFrame.x - diam;
self.vel.x *= -1;
}
else if (self.origin.x < 0){
self.vel.x *= -1;
self.location.x = 0;
}
if(self.origin.y > canvasFrame.y - diam){
self.location.y = canvasFrame.y - diam;
self.vel.y *= -1;
}
else if(self.origin.y < 0){
self.vel.y *= -1;
self.location.y = 0;
}
}
//Start C4Timer to run update every 1/60th of a second
- (void) run{
updateTimer = [C4Timer automaticTimerWithInterval:1/60.0f
target:self
method:#"update"
repeats:YES];
}
//Calculate a force to apply to mover
- (void)applyForce:(C4Vector *)force{
[force divideScalar:mass];
[self.accel add:force];
}
In my C4WorkSpace.m file:
#import "C4Workspace.h"
#import "Mover.h"
#implementation C4WorkSpace{
Mover *testMover;
NSMutableArray *moverArray;
}
-(void)setup {
C4Vector *gravity = [C4Vector vectorWithX:0.01f Y:0.0 Z:0.0f];
C4Vector *wind = [C4Vector vectorWithX:0 Y:0.4 Z:0];
moverArray = [[NSMutableArray alloc]init];
//Not using foo/bar variables right now, but usually use them to create CGPoint p
//int foo = arc4random() % (int)([self.canvas height]);
//int bar = arc4random() % (int)([self.canvas width]);
for (int i = 0; i < 500; i++) {
CGPoint p = CGPointMake(0,0);
Mover *m = [[Mover alloc]initWithPoint:p andCanvasController:self];
[moverArray addObject:m];
}
for (Mover *m in moverArray){
[self addShape:m];
[m run];
[m applyForce:gravity];
[m applyForce:wind];
}
}
#end
Sorry for how long this was, any and all help is much appreciated!

Show full screen on External Display for iOS

I just want to show full screen on External Display.
I'm using the code like this:
- (void) startTvOut {
NSArray *screens = [UIScreen screens];
CGSize max;
max.width = 0;
max.height = 0;
UIScreenMode *maxScreenMode = nil;
for (UIScreen *screen in screens)
{
if (screen != [UIScreen mainScreen])
{
for(int i = 0; i < [[screen availableModes] count]; i++)
{
UIScreenMode *current = [[screen availableModes] objectAtIndex: i];
if (current.size.width > max.width)
{
max = current.size;
maxScreenMode = current;
}
}
if (exWindow == nil)
{
exWindow = [[HUWindow alloc] initWithFrame:screen.brounds];
exWindow.backgroundColor = [UIColor whiteColor];
}
screen.overscanCompensation = UIScreenOverscanCompensationInsetBounds;
screen.currentMode = screen.preferredMode;
exWindow.screen = screen;
[exWindow makeKeyAndVisible];
m_isStarted = YES;
}
}
}
It can't show full screen on external device.
After I change the code
from
screen.overscanCompensation = UIScreenOverscanCompensationInsetBounds;
to
screen.overscanCompensation = UIScreenOverscanCompensationInsetApplicationFrame; it can show full screen, but the point (0,0) is not at the top of left screen.
My goal is to show the screen with full screen and have the point (0, 0) at the upper left corner of the screen. But it doesn't work.
Thanks in advance
Change this line:
screen.overscanCompensation = UIScreenOverscanCompensationInsetBounds;
to
screen.overscanCompensation = 3;
It's a non documented value...
For me the following code solved the problem (XCode 4, iOS 12.1)
screen.overscanCompensation = .scale
Before adding this line, I had the problem, that a black frame was around the screen.

Resources