Horizontal Scrollview to Swipe through coredata objects - core-data

I have an iOS app built on CoreData with tableviews and detailviews of the objects.
When in the detailview I would like to swipe horizontally to get the detail view of the next object.
I found PageControl and scrollview. But this is going to be for over 100 objects in the model.
Does anyone have a good sample of this or resource on how to do this.
Thanks
Michael

You could make individual views for each Core Data Object, then place those views on a UIScrollView.
You would need to set the contentSize:
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * allYourViews.count, scrollView.frame.size.height);
Then loop over all your views and add them to the scrollView:
for(int i = 0; i < allYourViews.count; i++) {
CGRect frame;
frame.origin.x = scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = scrollView.frame.size;
if(allYourViews.count > 0) {
UIView* someView = (UIView *)allYourViews[i];
someView.frame = frame;
[scrollView addSubview:someView];
}
}
For more information and how to make it scroll nicely, check this tutorial:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/
( I don't know how this will perform :-)

Related

How to remove an already drawn image in imageview in GridLayout in android studios?

In the gridlayout there are nine imageview in which some of the imageview image are drawn in a method.Now I want to remove the already drawn image in imageview in another method.I tried this but the app crashes.
GridLayout gridLayout = (GridLayout)findViewById(R.id.gridLayout);
for (int i = 0; i< gridLayout.getChildCount(); i++) {
((ImageView) gridLayout.getChildAt(i)).setImageResource(0);
try the following code. the logcat gives this error, since gridlayout is a legacy view, you have to do it the long way around. The code should find the gridlayout view and remove each child's image, thus reseting the grid.
androidx.gridlayout.widget.GridLayout grid = (androidx.gridlayout.widget.GridLayout)findViewById(R.id.gridLayout);
for (int i = 0; i < grid.getChildCount(); i++) {
((ImageView)grid.getChildAt(i)).setImageResource(0);
}

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;
}

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!

List view with custom view items with partially overlaps (Android)

I want to implement a list in Android that contains some customized views.
My problem is that I want the the views will be put one after the other with a little overlap between them. like in the following schema:
I also want to control this overlap in such a way that when the user clicks on one of the items, they will move apart from each other.
I tried to extend ListView but it seems to be very obscured, any suggestions?
Edit:
This can be more clear:
I did it by setting the divider height to -50dp.
this is exactly what I want to achieve, but somehow it doesn't reflect on my app.
I managed to achieve this by using scroll view with a single relative layout as a child.
I then dynamically place the views by defining a rule and margin:
for (int i = 0; i < 30; i++) {
TextView tv = new TextView(context);
tv.setText("Text \n Text" + i);
tv.setBackgroundColor(i % 2 == 0 ? Color.RED : Color.GREEN);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.leftMargin = 0;
lp.topMargin = (i * 45);
rl.addView(tv, lp);
}
Later, you can control the positioning of the sub-views by changing their y value (for example: if you want to add animation).
This is the final result:
This can probably be achieved by using the Camera.setTranslate function. See Android: Vertical ListView with overlaped rows and Android: vertical 3d listview for similar questions (with solutions)

tapku calendar color

I am using a TapkuMonthCalendarViewController in my application and when the calendar loads the color scheme of the calendar is not appearing normal on the simulator. Anyone else experience this?
I haven't messed with trying to set the background of anything and I have used this calendar before in other applications and it has never acted like this.
Any advice would be greatly appreciated.
This is the calendar view i see http://i.imgur.com/IwT9s.png
EDIT: I realized I forgot to include the bundle into my project! So this is the solution for all future tapku users.
You change calendar background than you can change the Calendar tile image .
OR You put this code on drawRect Method.
- (void) drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
//UIImage *tile = [UIImage imageWithContentsOfFile:TKBUNDLE(#"TapkuLibrary.bundle/Images/calendar/Month Calendar Date Tile.png")];
CGRect r = CGRectMake(0, 0, 46, 44);
//CGContextDrawTiledImage(context, r, tile.CGImage);
if(today > 0){
int pre = firstOfPrev > 0 ? lastOfPrev - firstOfPrev + 1 : 0;
int index = today + pre-1;
CGRect r =[self rectForCellAtIndex:index];
r.origin.y -= 7;
//[[UIImage imageWithContentsOfFile:TKBUNDLE(#"TapkuLibrary.bundle/Images/calendar/Month Calendar Today Tile.png")] drawInRect:r];
}
}

Resources