zoukankan      html  css  js  c++  java
  • 终于弄明白iPad UIPopoverController弹出窗口的位置和坐标了

    转载 http://xyyk.iteye.com/category/56505?show_full=true

    系统优化的我一愣一愣的,原来是下面的优化规则

    TodoViewController *contentViewController = [[TodoViewController alloc] init];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:contentViewController];

    navigationController.contentSizeForViewInPopover = CGSizeMake(100, 100); //内容大小

        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];

    popover.popoverContentSize = CGSizeMake(300, 300); //弹出窗口大小,如果屏幕画不下,会挤小的。这个值默认是320x1100

    CGRect popoverRect = CGRectMake(200, 700, 10, 10);

    [popover presentPopoverFromRect:popoverRect  //popoverRect的中心点是用来画箭头的,如果中心点如果出了屏幕,系统会优化到窗口边缘

     inView:self.view //上面的矩形坐标是以这个view为参考的

       permittedArrowDirections:UIPopoverArrowDirectionDown  //箭头方向

       animated:YES];

    [contentViewController release];

    [navigationController release];

    //最佳实践,使用哪个view做参考,就以哪个view的bounds送进去就好了,箭头自动指向这个view的中心

    UINavigationBar自定义导航栏背景和按钮,完美支持横屏竖屏旋转,视图控制器可以分别使用自己的导航栏


    此方法可以通过Apple审核,导航上的按钮背景需要做,否则看起来不那么和之又谐

    //CustomNavigationBar.h
    @interface UINavigationBar (UINavigationBarCategory)
    UIImageView *backgroundView;
    - (void)setBackgroundImage:(UIImage*)image;
    - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
    @end
    
    //CustomNavigationBar.m
    @implementation UINavigationBar (UINavigationBarCategory)
    -(void)setBackgroundImage:(UIImage*)image
    {
    	if(image == nil)
    	{
    		[backgroundView removeFromSuperview];
    	}
    	else
    	{
    		backgroundView = [[UIImageView alloc] initWithImage:image];
    		backgroundView.tag = 1;
    		backgroundView.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height);
    		backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    		[self addSubview:backgroundView];
    		[self sendSubviewToBack:backgroundView];
    		[backgroundView release];
    	}
    }
    
    //for other views
    - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
    {
    	[super insertSubview:view atIndex:index];
    	[self sendSubviewToBack:backgroundView];
    }
    @end
    
    //YourViewController.m
    - (void)viewWillAppear:(BOOL)animated
    {
    	[super viewWillAppear:animated];
    	[self.navigationController.navigationBar
    		setBackgroundImage:[UIImage imageNamed:@"navigation_bar_bg.png"]];
    }

    创建按钮

    	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    	button.frame = CGRectMake(10.0, 10.0, 100.0, 40.0);
    	[button setTitle:@"Normal" forState:UIControlStateNormal];
    	UIImage *image = [UIImage imageNamed:@"normal.png"];
    	UIImage *newImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
    	[button setBackgroundImage:newImage forState:UIControlStateNormal];
    	button.adjustsImageWhenHighlighted = NO;
    	[button addTarget:self action:@selector(buttonSwitch:) forControlEvents:UIControlEventTouchDown];
    	[self.view addSubview:button];

    事件处理

    -(void)buttonSwitch:(id)sender
    {
    	static BOOL isHighlighted = NO;
    	
    	UIButton *button = (UIButton*)sender;
    	UIImage *image = nil;
    	NSString *title = nil;
    	if (isHighlighted)
    	{
    		title = @"Normal";
    		image = [UIImage imageNamed:@"normal.png"];
    	}
    	else
    	{
    		title = @"Hightlight";
    		image = [UIImage imageNamed:@"highlight.png"];
    	}
    	
    	[button setTitle:title forState:UIControlStateNormal];
    	UIImage *newImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
    	[button setBackgroundImage:newImage forState:UIControlStateNormal];
    	isHighlighted = !isHighlighted;
    }
     

    Xcode代码提示生成源代码程序块默认格式如下,注意左花括号的位置:

    if ( condition ) {
        do ...
    }

    因为以前的使用习惯,我想让自动生成的左右花括号都单独成行,变成下面的样子:

    if ( condition )
    {
        do ...
    }

    在Terminal里面,运行下面命令,然后重启Xcode:

    defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\n"
    这个命令修改了~/Library/Preferences/com.apple.Xcode.plist,这是Xcode的配置文件

    比如地图导航数据G级别的数据,模拟器调试的时候将是个恶梦

    后面要做一个导航类应用程序,所以未雨绸缪先纪录下来

    设备调试时,把测试数据尽量最小化吧

    模拟器调试时,使用固定路径,指定到程序外路径,模拟器貌似没有沙盒,下面代码在模拟器里是可以读取文件的。设备调试时改为resources

    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"/Users/george/Desktop/Test.plist"];
  • 相关阅读:
    Code Forces Gym 100886J Sockets(二分)
    CSU 1092 Barricade
    CodeChef Mahesh and his lost array
    CodeChef Gcd Queries
    CodeChef GCD2
    CodeChef Sereja and LCM(矩阵快速幂)
    CodeChef Sereja and GCD
    CodeChef Little Elephant and Balance
    CodeChef Count Substrings
    hdu 4001 To Miss Our Children Time( sort + DP )
  • 原文地址:https://www.cnblogs.com/chen1987lei/p/2077639.html
Copyright © 2011-2022 走看看