iOS 7 view controller layout issue with transparent/blurred nav bar - layout

I am having trouble with my view controllers in iOS 7. I'm trying to figure out the best way to adjust my view's layout under the nav bar and status bar while maintaining the transparency/blur of the nav bar. So for example, if I have a view controller with:
def viewDidLoad
#scroll = UIScrollView.alloc.initWithFrame(new_frame)
#scroll.bounces = true
#scroll.delegate = self
#scroll.alwaysBounceVertical = true
#scroll.scrollsToTop = true
#scroll.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, scroll_frame.size.height)
self.view.addSubview(#scroll)
end
My content appears under the nav bar, which I get given the iOS 7 transition guide. To correct that, if I add the following inside of viewDidLoad:
self.edgesForExtendedLayout = UIRectEdgeNone
The layout is adjusted but the navbar no longer has transparency or blur because the view doesn't extend behind it.
If I don't adjust scrollView insets instead of setting edges for layout:
self.automaticallyAdjustsScrollViewInsets = false
Then change my scroll frame to:
def viewDidLoad
nav_bar_height = self.navigationController.navigationBar.frame.size.height
status_height = UIApplication.sharedApplication.statusBarFrame.size.height
height = nav_bar_height + status_height
scroll_frame = self.view.bounds
new_frame = CGRect.new([0, height], [scroll_frame.size.width, scroll_frame.size.height])
#scroll = UIScrollView.alloc.initWithFrame(new_frame)
#scroll.bounces = true
#scroll.delegate = self
#scroll.alwaysBounceVertical = true
#scroll.scrollsToTop = true
#scroll.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, scroll_frame.size.height)
self.view.addSubview(#scroll)
end
I no longer get the transparent/blur of the nav bar. Only when I adjust the scroll's frame - at the x origin - with a new height does this seem to happen. So I'm wondering why that is and how I can best adjust my scroll without losing the blur/transparency.

Maybe you can try with inset
[scroll setContentInset:UIEdgeInsetsMake(nav_bar_height + status_height, 0.0, 0.0, 0.0)];
[scroll setScrollIndicatorInsets:UIEdgeInsetsMake(nav_bar_height + status_height,0.0,0.0,0.0)];
Hope that help

Related

Drag & Drop (swap) 3 texture buttons in a Margin Container->VBox

Following along a great tutorial, code is replicated yet does not function as shown. No new texture appears to be created when I try to drag the texture button. Only difference is the tutorial uses a TextureRect, while I'm using a TextureButton.
extends TextureButton
func get_drag_data(position: Vector2):
var vControl = Control.new()
var vData = {}
var vTexture = TextureRect.new()
vTexture.expand = true
vTexture.texture = texture_disabled
vTexture.rect_size = Vector2(320, 400)
vControl.add_child(vTexture)
vTexture.rect_position = -0.5 * vTexture.rect_size
set_drag_preview(vTexture)
return vData
Code above is attached to Party_1. texture_disabled does have a texture set.
It would work if you had the code in get_drag_data looking like this:
func get_drag_data(_position: Vector2):
var vTexture = TextureRect.new()
vTexture.expand = true
vTexture.texture = texture_disabled
vTexture.rect_size = Vector2(320, 400)
set_drag_preview(vTexture)
return {}
However, that would place the TextureRect top-left corner at the cursor position.
You want to offset the position of the TextureRect so it is centered at the cursor position. To do that, you create another Control, add the TextureRect as a child to it… And pass the TextureRect anyway? No, that does not work, you need to pass the new Control:
func get_drag_data(_position: Vector2):
var vTexture = TextureRect.new()
vTexture.expand = true
vTexture.texture = texture_disabled
vTexture.rect_size = Vector2(320, 400)
var vControl = Control.new()
vControl.add_child(vTexture)
vTexture.rect_position = -0.5 * vTexture.rect_size
set_drag_preview(vControl)
return {}
Please notice I'm giving vControl to set_drag_preview, not vTexture.
You cannot give to set_drag_preview a Control that has a parent. In fact, if you tried you would get an error in the Output console saying:
_gui_set_drag_preview: Condition "p_control->get_parent() != nullptr" is true.
Or
_gui_set_drag_preview: Condition "p_control->is_inside_tree()" is true.

kendo dialog window out of bounds at multiple uploads selected

I have an issue regarding a kendo dialog window including an upload.
When I upload multiple elements the list gets longer and longer and at some point gets bigger than my browserwindow and runs out of bounds at the bottom of the screen.
The insert button then is below the bottom bound of the browser but the browser doesn't allow me to scroll (firefox + chrome).
How can I limit my window to the browser screen and not exceed it?
#(Html.Kendo().Dialog()
.Name("ImageBrowser")
.Content( Html.Partial("ImageBrowserContent").ToString())
.MinWidth(400)
.MinHeight(800)
.MaxHeight(1000)
.MaxWidth(800)
.Modal(true)
.Visible(false)
)
#(Html.Kendo().Upload()
.Name("imageUpload")
.Messages(mess => mess.Select("Upload"))
.Async(a => a
.Save("Upload", "Image")
.Remove("RemoveUpload", "Image")
.AutoUpload(true)
)
)
I have provided a dojo here for you which hopefully is what you are after.
https://dojo.telerik.com/eqaZibIL
It uses the javascript version but you can just apply the function I have created to the dialog initial event. like so:
#Html.Kendo().Dialog().Events(e => e.InitOpen("dialog_resize"))
(This is some code I have modified for handling kendoWindow's so could be optimized more I think)
function dialog_resize() {
//THIS GETS THE POPUP DIALOG
var popUpDialog = $('#dialog').data("kendoDialog");
//THIS GETS THE CONTENT AREA FOR THE ENTIRE DIALOG
var contentArea = $(".k-widget.k-window.k-dialog");
//THIS GETS THE ACTUAL CONTENT AREA OF THE DIALOG IE.WHAT YOU WANT DISPLAYED
var innerForm = $("#dialog");
var windowHeight = $(window).innerHeight();
var windowWidth = $(window).innerWidth();
//CALCULATE THE WIDTH OF THE DIALOG AND SET IT TO 80%
//OF SCREEN REALESTATE TO STRECH OUT.
//NOT REQUIRED IF YOU ARE SETTING THE WIDTH MANUALLY.
contentArea.width(windowWidth * 0.8)
//CENTER THE DIALOG ON THE SCREEN.
popUpDialog.center();
//GET 97% OF THE AVAILABLE DIALOG CONTENT AREA TO SHOW Y-SCROLL BAR
var fixedHeight = (contentArea.height() * 0.97);
var fixedWidth = contentArea.width() * 0.965;
//SET THE HEIGHT, WIDTH AND SCROLL BAR OF THE CONTENT AREA
//SHOWING BLUE BORDER TO SHOW THE ITEM IS POSITIONING CORRECTLY IN DIALOG
innerForm.height(fixedHeight).width(fixedWidth).css({
maxHeight: fixedHeight + 'px !important',
maxWidth: fixedWidth + 'px !important',
overflowY: 'scroll',
overflowX: 'hidden',
border: '1px solid blue'
});
}
Hopefully you can follow what is going off here.
As long as you have set the maxHeight for the dialog on initialization all this seems to work correctly. I have applied a blue border to the content area just for demo purposes so you can see it in action.

Get Navigation bar height in xamarin forms?

I am working on a project where i need to get the navigation bar height.I am getting the whole screen height using:
Helpers.ApplicationContext.ScreenHeight = (int)Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density;
Helpers.ApplicationContext.ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density;
But I am not able to get the navigation bar height.
Can any one please suggest an idea to get the navigation bar height of my page.
Thanks in advance.
For iOS This may help you :
var navbarHeight = YourViewControllerInstance.NavigationController?.NavigationBar.Frame.Height;
For Android :
TypedArray styledAttributes = this.Theme.ObtainStyledAttributes(
new int[] { Android.Resource.Attribute.ActionBarSize });
var actionbarHeight = (int) styledAttributes.GetDimension(0, 0);
styledAttributes.recycle();
Above example gives Height in Pixel. Please find more refined sample as below which provide height in Pixel as well as DP:
TypedValue tv = new TypedValue();
int actionBarHeightInPixel = 0;
int actionBarHeightInDP = 0;
DisplayMetrics metrics = Resources.DisplayMetrics;
if (Theme.ResolveAttribute(Resource.Attribute.actionBarSize, tv, true))
{
actionBarHeightInPixel = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
actionBarHeightInDP = actionBarHeightInPixel / (int)metrics.Density;
}

Debugging this jade+coffeescript code on Express4 server

I am looking for some help as I don't know how bad those lines of codes are.
I am trying to adapt this original Codepen.io work (http://codepen.io/ettrics/pen/Jdjdzp/ , by Ettrics) for one of my teaching project. I run my web page on a Express4+Stylus+Coffescript Node's server.
The CoffeeScript file:
# Each popup takes the entire window, so it is a modal
Modal = ->
# Make it easier for yourself by not having to type as much to select an element (QuerySelectorAll)
$qsa = (el) ->
document.querySelectorAll(el)
trigger = $qsa('.modal__trigger') # What you click to activate the modal
modals = $qsa('.modal') # The entire modal (takes up entire window)
modalsbg = $qsa('.modal__bg') # The entire modal (takes up entire window)
content = $qsa('.modal__content') # The inner content of the modal
closers = $qsa('.modal__close') # An element used to close the modal
isOpen = false
contentDelay = 100 # Duration after you click the button and wait for the content to show
len = trigger.length
getId = (event) ->
event.preventDefault()
# Get the value of the data-modal attribute from the button
modalId = this.dataset.modal
# Remove the '#' from the string
len = modalId.length
modalId = modalId.substring(1, len)
# Select the modal we want to activate
modal = document.getElementById(modalId)
# Execute function that creates the temporary expanding div named fakeDiv
makefakeDiv(this, modal)
makefakeDiv = (self, modal) ->
fakeDiv = document.getElementById('modal__temp');
# If there isn't a 'fakeDiv', create one and append it to the button that was
# clicked. after that execute the function 'moveTrigger' which handles the animations.
if fakeDiv?
fakeDiv = document.createElement('div')
fakeDiv.id = 'modal__temp'
self.appendChild(fakeDiv)
moveTrigger(self, modal, fakeDiv)
moveTrigger = (trigger, modal, div) ->
triggerProps = trigger.getBoundingClientRect()
modalProps = modal.querySelector('.modal__content').getBoundingClientRect()
xc = window.innerWidth / 2
yc = window.innerHeight / 2
######## VOIR LE CSS !!
# This class increases z-index value so the button goes overtop the other buttons
trigger.classList.add('modal__trigger--active')
# These values are used for scale the fakeDiv div to the same size as the modal
scaleX = modalProps.width / triggerProps.width
scaleY = modalProps.height / triggerProps.height
scaleX = scaleX.toFixed(3) # Round to 3 decimal places
scaleY = scaleY.toFixed(3)
# These values are used to move the button to the center of the window (to pepare the ease out effect)
transX = Math.round(xc - triggerProps.left - triggerProps.width / 2)
transY = Math.round(yc - triggerProps.top - triggerProps.height / 2)
# If the modal is aligned to the top then move the button to the center-y of the modal instead of the window
if modal.classList.contains('modal--align-top')
transY = Math.round(modalProps.height / 2 + modalProps.top - triggerProps.top - triggerProps.height / 2)
# Translate button to center of screen
trigger.style.transform = 'translate(' + transX + 'px, ' + transY + 'px)'
trigger.style.webkitTransform = 'translate(' + transX + 'px, ' + transY + 'px)'
# Expand fakeDiv to the same size as the modal
div.style.transform = 'scale(' + scaleX + ',' + scaleY + ')';
div.style.webkitTransform = 'scale(' + scaleX + ',' + scaleY + ')'
# Smart animation API used to open
window.setTimeout( ->
window.requestAnimationFrame(open(modal, div))
, contentDelay)
open = (modal, div) ->
if !isOpen
# Select the content inside the modal
content = modal.querySelector('.modal__content')
# Reveal the modal
modal.classList.add('modal--active')
# Reveal the modal content
content.classList.add('modal__content--active')
###
# When the modal content is finished transitioning, fadeout expanding
# fakeDiv so when the window resizes it isn't visible ( it doesn't
# move with the window).
###
content.addEventListener('transitionend', hidefakeDiv, false)
isOpen = true
hidefakeDiv = ->
# Fadeout fakeDiv so that it can't be seen when the window is resized
div.style.opacity = '0'
content.removeEventListener('transitionend', hidefakeDiv, false)
close = (event) ->
event.preventDefault()
event.stopImmediatePropagation()
target = event.target
div = document.getElementById('modal__temp')
###
# Make sure the modal__bg or modal__close was clicked, we don't
# want to be able to click inside the modal and have it close.
###
if isOpen and target.classList.contains('modal__bg') or target.classList.contains('modal__close')
# Make the hidden div visible again and remove the transforms so it scales back to its original size
div.style.opacity = '1'
div.removeAttribute('style')
###
# Iterate through the modals, modal contents and triggers to remove their active classes.
# Remove the inline css from the trigger to move it back into its original position.
###
for i in [0..len]
modals[i].classList.remove('modal--active')
content[i].classList.remove('modal__content--active')
trigger[i].style.transform = 'none'
trigger[i].style.webkitTransform = 'none'
trigger[i].classList.remove('modal__trigger--active')
# When fakeDiv opacity is 1 again, we want to remove it from the dom
div.addEventListener('transitionend', removeDiv, false)
isOpen = false
removeDiv = ->
setTimeout( ->
window.requestAnimationFrame(div.remove())
, contentDelay - 50)
bindActions = ->
for i in [0..len]
trigger[i].addEventListener('click', getId, false)
closers[i].addEventListener('click', close, false)
modalsbg[i].addEventListener('click', close, false)
init = ->
bindActions()
{init: init}
window.onload = Modal.init
This coffeescript file is called in jade by
script(src='javascripts/coffee-script.js')
script(src='javascripts/modal.coffee', type='text/coffeescript')
I could not use the CoffeeScript compiler logs because the of the 'window.onload = Modal.init' which returned a "window is not defined" error. But browser console returns no error, Codepen neither.
I have to confess that I began to learn these 4 languages 3 days ago. So I basically don't know anything about anything... I don't even know if my app settings are right.
Can anyone give me a hand on this?
Thanks a lot! :)

Positioning sprites inside scene

I would like when i create all my sprites to get centred in the screen, but that is not the case, i have a sprite when i set it's position to CGPointMake(self.size.width / 2, self.size.height / 2) it gets centred vertically but not horizontally, when i set it to CGPointMake(0, 0) it sets at the bottom of the screen with only half of it's body visible ( which is what you expect) but horizontally it doesn't get positioned right ( half his vertical body appears ) until i set it's X to 300.
How come the sprite's Y position gets set right but the X doesn't ?
scene.scaleMode = .AspectFill
and i haven't set any anchorPoint, 4' screen.
UPDATE:
I'm using Portrait, played around with different scaleMode and found out that the perfect (0, 0) that sets the sprite on the bottom left is:
scene.scaleMode = .ResizeFill
It also works fine with different screen sizes,but (self.size.width / 2) puts it further to the left.Do you think it's the best setting for all SpriteKit Portrait projects?
I tried to reproduce what you are saying, but I couldn't, either using .sks file or not for loading the scene. Also I've produced good results on both 7.1 and 8.1 simulators...The thing is that simulators sometimes could be tricky and not 100% reliable, so you should not trust them much.
I don't know if this will help you, but you should consider it...In Xcode 5 projects scene is programmatically created to have a size of the view. Basically it's done in viewDidLoad method like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
Or using viewWillLayoutSubviews like LearnCocos2D pointed:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
skView.showsDrawCount = YES;
//skView.showsQuadCount = YES;
skView.showsPhysics = YES;
skView.ignoresSiblingOrder = YES;
if(!skView.scene){
// Create and configure the scene.
GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
But Xcode 6 uses an SKS file:
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
}
}
If you look at the GameScene.sks you can see that the default scene size is 1024x768.
Try to print your scene size as well as view's bounds size to see actuall sizes. You can use something like:
println("view.bounds\(view.bounds), self.size\(self.size)")
I don't know if any of this helped, but I hope it will lead you somewhere. Goodluck!

Resources