苹果有介绍:

引用
-webkit-touch-callout
Disables the default callout shown when you touch and hold a touch target.

Syntax
-webkit-touch-callout: behavior;


可以在css里设定:

body{margin:0;padding:0;-webkit-touch-callout:none;}


或者在object-c里设置,在网页加载完成webViewDidFinishLoad时:

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];


前者适合自己控制的网页,不用改app,后者就适合所有的网页了。

https://developer.apple.co...
没有与时俱进,发现从ios5以来,居然不知道怎么处理旋转控制了

首先,appdelegate里面可以控制全局的,比如控制ipad随便转,iphone不转:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // iPad
        return UIInterfaceOrientationMaskAll;
    } else {
        // iPhone / iPod Touch
        return UIInterfaceOrientationMaskPortrait;
    }
    
}


其次,如果需要每个去控制,可以是这样:

How to support one or more landscape controllers in app that is portrait mainly in ios6:

1) in AppDelegate

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        UINavigationController* ns = (UINavigationController*)self.window.rootViewController;
        if (ns) {
            UIViewController* vc = [ns visibleViewController];
//by this UIViewController that needs landscape is identified
            if ([vc respondsToSelector:@selector(needIos6Landscape)])
                return [vc supportedInterfaceOrientations];

        }
        return UIInterfaceOrientationMaskPortrait; //return default value
    }


2) in UIView controller(s) that needs landscape (or portrait+lanscape etc):

//flag method
-(void)needIos6Landscape {
}
- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}


3) in controllers, to which you can RETURN from controllers, that can be rotated in landscape - this is important, otherwise they remaind landscape on return from landscape-enabled VC.

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


4) (maybe not needed, but for sure..) - subclass navigation controller(s) you using, and add:

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController* vc = [self visibleViewController];
    if (vc) {
        if ([vc respondsToSelector:@selector(needIos6Landscape)]) {
             return [vc supportedInterfaceOrientations];
        }
    }
    return UIInterfaceOrientationMaskPortrait;
}


The important step is to ask for orientation only controllers from your app, because during transition between controllers, for some time there is some system controller as root, and will return incorrect value (this took me 2 hrs to find out, it was reason it was not working).

引自:http://stackoverflow.com/q...
问题描述:

赋予imageView一个图片,在单元格里显得太满,图片随行高调整高度。
如何调整适当留下边距?

有两个方式都可以考虑:

1 继承UITableViewCell,重写如下方法:
-(void)layoutSubviews
{
[super layoutSubviews];
[self.imageView setFrame:CGRectMake(10, 10,29, 29)];
self.imageView.contentMode = UIViewContentModeScaleAspectFit; //Fill也可以
}


2 改变图片时,代码调整:

CGSize itemSize = CGSizeMake(40, 40);

UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];

cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


但都有一个问题,如果图片不是方的,点击后,就会变成原来的比例
可以禁止选择的状态,如:
cell.selectionStyle = UITableViewCellSelectionStyleNone;

参考:http://www.oschina.net/question/852721_75288
如果用actionSheet问用户选项,然后选择做啥

    UIActionSheet *actionSheet= [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相片库选取", nil];
    [actionSheet showInView:self.view];


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    selectedIndex = buttonIndex;
        if (selectedIndex == 0) {
            [self addCarema];
        }else if (selectedIndex == 1){
            [self openPicLibrary];
        }
}


openPicLibrary唤不起窗体,会有错误

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:picker animated:YES completion:^{
        }];


比如类似错误

Warning: Attempt to present   on xxxx which is already presenting (null)

参考解决方式:

引用
I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController until the next iteration of the runloop, by doing this:


[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self openPhotoPicker:sourceType];
}];


本例的解决办法是:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    selectedIndex = buttonIndex;
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        if (selectedIndex == 0) {
            [self addCarema];
        }else if (selectedIndex == 1){
            [self openPicLibrary];
        }
    }];
}


或者是记下点击的index,在动画结束的时候处理:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (selectedIndex == 0) {
        [self addCarema];
    }else if (selectedIndex == 1){
        [self openPicLibrary];
    }
}


参考页面: http://stackoverflow.com/questions/24942282/uiimagepickercontroller-not-presenting-in-ios-8


解析JSON数据,转换为NSData格式

            NSError *jsonError;
            NSData *objectData = [content2 dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary *result = [NSJSONSerialization JSONObjectWithData:objectData
                                                                 options:NSJSONReadingMutableContainers
                                                                   error:&jsonError];


数值转换为字符串

    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myDictionary
                                                       options:0 // OR NSJSONWritingPrettyPrinted
                                                         error:&error];
    NSString *jsonString;
    if (! jsonData) {
        NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
        jsonString = @"{}";
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }


NSJSONWritingPrettyPrinted是可读性的字符串,0则不换行的格式
分页: 3/26 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐