Show full screen on External Display for iOS - 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.

Related

CCScrollView scroll and touch events never firing

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]

How to show resized sidebar using SWRevealViewController?

I am using SWRevealViewController in IOS app (universal). I'm getting sidebar in iPhone and iPad both but I want to show sidebar which covers 90% of screen - how can I?
open the SWRevealViewController.m file and then u get the _initDefaultProperties Method. in this method you get the side screen size and position
- (void)_initDefaultProperties
{
_frontViewPosition = FrontViewPositionLeft;
_rearViewPosition = FrontViewPositionLeft;
_rightViewPosition = FrontViewPositionLeft;
_rearViewRevealWidth = 260.0f; /// this is the method u change the side bar width
_rearViewRevealOverdraw = 60.0f;
_rearViewRevealDisplacement = 40.0f;
_rightViewRevealWidth = 260.0f;
_rightViewRevealOverdraw = 60.0f;
_rightViewRevealDisplacement = 40.0f;
_bounceBackOnOverdraw = YES;
_bounceBackOnLeftOverdraw = YES;
_stableDragOnOverdraw = NO;
_stableDragOnLeftOverdraw = NO;
_presentFrontViewHierarchically = NO;
_quickFlickVelocity = 250.0f;
_toggleAnimationDuration = 0.25;
_frontViewShadowRadius = 2.5f;
_frontViewShadowOffset = CGSizeMake(0.0f, 2.5f);
_frontViewShadowOpacity = 1.0f;
_userInteractionStore = YES;
_animationQueue = [NSMutableArray array];
_draggableBorderWidth = 0.0f;
}
Just have an if statement to determine the correct size of the sidebar. something like this:
if(device == iPad)
_rearViewRevealWidth = 600.0f;
else if(device == iPhone)
_rearViewRevealWidth = 260.0f;
open the SWRevealViewController.m file and then you get the _initDefaultProperties Method.
- (void)_initDefaultProperties
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
float x=(appDelegate.windowWidth)*9/10; //windowWidth=self.window.bounds.size.width;
float y=x-260;
_frontViewPosition = FrontViewPositionLeft;
_rearViewPosition = FrontViewPositionRightMost;
_rightViewPosition = FrontViewPositionLeft;
_rearViewRevealWidth = x;
_rearViewRevealOverdraw = 60.0f+y;
_rearViewRevealDisplacement = 40.0f+y;
....
}
You can do something like this...
When you have subclass from SWRevealViewController...
call property for this problem and set as you want...
Hope it's help someone...
self.rightViewRevealWidth = [UIScreen mainScreen].bounds.size.width * 0.9;

UIImageView animationDuration with fade effects

I'am searching for a (very) simple way to crossfade images within animationDuration time. I tried using NSTimer and some other stuff I found here, but no solution satisfy or helps me.
I create this stuff in a method (without comments) ...
- (UIImageView *)playSequence{
NSArray *structureArray = self.contenManager.ImageViewControllerSize;
NSMutableArray *structuresToPlay = [[NSMutableArray alloc] init];
// walk thru current collection
for(NSInteger i = 0; i < [self.currentCollection count]; i++)
{
NSInteger index = [[self.currentCollection objectAtIndex:i] integerValue];
[structuresToPlay addObject:[UIImage imageNamed:[structureArray objectAtIndex:index]]];
}
_playSequence = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
_playSequence.animationImages = structuresToPlay;
_playSequence.animationDuration = 5 * structuresToPlay.count;
[_playSequence startAnimating];
return _playSequence;
}
Here is the part where the method is called ...
- (void)justPlaySelection
{
UIView *justPlaySelection = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
// some background music code ...
// add play sequence
[justPlaySelection addSubview:self.playSequence];
// add close button
// { ... }
[self presentSemiView:justPlaySelection];
}
- (UIImageView *)playSequence
{
if (_playSequence == nil)
{
NSArray *structureArray = self.contenManager.ImageViewControllerSize;
NSMutableArray *structuresToPlay = [[NSMutableArray alloc] init];
// walk thru current collection
for(NSInteger i = 0; i < [self.currentCollection count]; i++)
{
NSInteger index = [[self.currentCollection objectAtIndex:i] integerValue];
[structuresToPlay addObject:[UIImage imageNamed:[structureArray objectAtIndex:index]]];
}
_playSequence = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
}
_playSequence.animationImages = structuresToPlay;
_playSequence.animationDuration = 5 * structuresToPlay.count;
[_playSequence startAnimating];
return _playSequence;
}
Here is another way to switch between to UIImageViews, it wouldn't be hard to add in the fade in and out.
- (void) performAnimationOfFrameAtIndex:(NSNumber*)indexNum
{
int index = indexNum.intValue;
BOOL completedSequece = index >= [self.frames count];
if (completedSequece) return;
UIImageView *imgIn;
UIImageView *imgOut;
if (index % 2 == 0) {
imgIn = self.animationImageViewOne;
imgOut = self.animationImageViewTwo;
}
else {
imgIn = self.animationImageViewTwo;
imgOut = self.animationImageViewOne;
}
imgIn.image = [self.frames objectAtIndex:index];
[self.view sendSubviewToBack:imgOut];
double speed = 0.1;
[self performSelector:#selector(performAnimationOfFrameAtIndex:) withObject:[NSNumber numberWithInt:index + 1] afterDelay:speed];
}
I created a project that does exactly what you describe (an effect like UIImageView animation sequence, but with a cross-fade between images.)
The project is on github: https://github.com/DuncanMC/Animate-Img
You need to have 2 image views.
The trick I use is to stack them on top of each other, and simply animate the top image view from alpha 1 -> 0, then switch images in the top image view and animate it from alpha 0 -> 1.0, so the new image is revealed.
The project demos a morph transition using only 5 frames. Each frame is marked with a number so you can see the frame changes. It has a switch which lets you turn cross-fading on or off.

Setting UIScreen's mode / resolution

I have to set the external UIScreen's mode to run with the resolution 1024x768.
First I search if the screen supports this resolution:
if ([[UIScreen screens] count] > 1){
CGSize size1024;
size1024.height = 0;
size1024.width = 0;
UIScreenMode *screenMode1024 = nil;
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
for(int i = 0; i < [[secondScreen availableModes] count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens] objectAtIndex:1] availableModes] objectAtIndex: i];
if (current.size.width == 1024.0 && current.size.height == 768.0)
{
size1024 = current.size;
screenMode1024 = current;
break;
}
}
}
After that I set the external screen's mode to use this resolution, but somehow it does not work and the screen is using other, the default resolution.
secondScreen.currentMode = screenMode1024;
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame: CGRectMake(0,0, size1024.width, size1024.height)];
secondWindow.screen = secondScreen;
...
secondWindow.hidden = NO;
Any help ? Maybe I missed some settings ? I also tried with this :
[[[UIScreen screens] objectAtIndex:1] setCurrentMode:screenMode1024];
I found the solution.
The problem was that the screen's mode has to be changed when the external screen is connected to the iOS device.
[[NSNotificationCenter defaultCenter] addObserver: self selector:#selector(screenDidConnectNotification:) name: UIScreenDidConnectNotification object: nil];
The screen mode should be changed inn the screenDidConnectNotification function.

transform image when it hits the edge of the screen in iOS

I have 10 fireflies that I make "fly" around the screen using the code below.
The code also serves to keep the fireflies on the screen.
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *blueArray = [NSArray array];
blueArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"blue1.png"],
[UIImage imageNamed:#"blue2.png"], nil];
blue.animationImages = blueArray;
blue.animationDuration = 0.20;
blue.animationRepeatCount = -1;
[blue startAnimating];
bluepos =CGPointMake(2.0, 1.5);
}
-(void) someMethod {
endingAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:(0.03) target:self selector:#selector(makeFly) userInfo:nil repeats:YES];
}
-(void) makeFly {
blue.center = CGPointMake(blue.center.x+bluepos.x, blue.center.y+bluepos.y);{
if(blue.center.x > 480 || blue.center.x <0)
bluepos.x = -bluepos.x;
if(blue.center.y > 320 || blue.center.y <0)
bluepos.y = -bluepos.y;
}
}
The "flying" works great except that when the fireflies hit the edge of the screen and reverse direction to keep them on the screen the firefly image itself is still "facing" the othe direction so it looks like they are flying backwards half the time.
I want to set it up so that when the fireflies hit the edge of the screen they reverse direction AND the image itself is reversed.
I tried this:
In .h
#property (nonatomic, assign) BOOL blueIsFacingRight;
In .m
#synthesize blueIsFacingRight;
-(void) makeFly {
blue.center = CGPointMake(blue.center.x+bluepos.x, blue.center.y+bluepos.y); {
if(blue.center.x > 480 ) {
if (blueIsFacingRight == YES) {
blue.transform = CGAffineTransformMakeScale(-1, 1);
blueIsFacingRight = NO;
}
bluepos.x = -bluepos.x;
}
if(blue.center.x <0) {
bluepos.x = -bluepos.x;
if (blueIsFacingRight == NO) {
blue.transform = CGAffineTransformMakeScale(1, 1);
blueIsFacingRight = YES;
}
}
if(blue.center.y > 320 )
bluepos.y = -bluepos.y;
if( blue.center.y <0)
bluepos.y = -bluepos.y;
}
}
I thought this would work but the image does not reverse when it hits the "wall"
Can anyone explain why this does not work and if there is a better why to accomplish the effect im looking for?
You are setting the transform X value to -1 in both cases. When its facing right you should set transform like this CGAffineTransformMakeScale(1, 1);
blue.center = CGPointMake(blue.center.x+bluepos.x, blue.center.y+bluepos.y); {
if(blue.center.x > 480 ) {
if (blueIsFacingRight == YES) {
blue.transform = CGAffineTransformMakeScale(-1, 1);
blueIsFacingRight = NO;
}
bluepos.x = -bluepos.x;
}
if(blue.center.x <0) {
bluepos.x = -bluepos.x;
if (blueIsFacingRight == NO) {
blue.transform = CGAffineTransformMakeScale(1, 1);
blueIsFacingRight = YES;
}
}
**blue.transform =CGAffineTransformIdentity;**
THe above was in my makeFly method with a bunch of other stuff above where I was reversing the image so I was undoing the change the very next time the method was called ( 0.03 later)
Man I feel stupid

Resources