小编Har*_*ain的帖子

以编程方式在UIButton上设置图像和文本

我需要以编程方式创建按钮,用于正常和突出显示的状态以及文本.我无法使用Interface Builder构建它,因为我需要在a上创建按钮UIScrollView.这是我到目前为止的代码:

- (void)loadView {
    CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
    scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
    scrollView.contentSize=CGSizeMake(320,960);

    UIImageView *tempImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpeg"]];

    UIImage * buttonImage = [UIImage imageNamed:@"contentlist_active.png"];

    self.view=scrollView;
    [scrollView addSubview:tempImageView2];

    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(22, 100, 277, 32);

    [btn setImage:buttonImage forState:UIControlStateNormal]; 

    [btn setTitle:@"hello world" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [scrollView addSubview:btn];

}
Run Code Online (Sandbox Code Playgroud)

但是按钮上的文字没有显示.如果我注释掉了setImagefor button,则文本显示完美,否则不显示.我可以同时同时拥有文字和图片吗?

iphone ios4 ios xcode4.2

41
推荐指数
3
解决办法
7万
查看次数

SKSpriteNode - 创建一个圆角节点?

有没有办法让SKSpriteNode圆形走投无路?我正在尝试用颜色填充的SKSpriteNode创建一个Tile likesqaure块:

SKSpriteNode *tile = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0.0/255.0
                                                                           green:128.0/255.0
                                                                            blue:255.0/255.0
                                                                           alpha:1.0] size:CGSizeMake(30, 30)];
Run Code Online (Sandbox Code Playgroud)

如何围绕走投无路?

谢谢!

iphone objective-c ios sprite-kit

31
推荐指数
5
解决办法
2万
查看次数

如何在UIButton子类中设置UIButton类型

我是UIButton的子类,我想要的是将按钮类型设置为Round Rect.

Button.h

@interface Button : UIButton {}
    - (void)initialize;
@end
Run Code Online (Sandbox Code Playgroud)

Button.m

@implementation Button

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}


-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if(self){
        [self initialize];
    }
    return self;
}

- (void)initialize
{
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    self.titleLabel.textColor = [UIColor redColor];
    self.titleLabel.textAlignment = UITextAlignmentCenter;
   //[UIButton buttonWithType:UIButtonTypeRoundedRect];
}

@end
Run Code Online (Sandbox Code Playgroud)

在这里我尝试[UIButton buttonWithType:UIButtonTypeRoundedRect]但它不起作用.任何人都可以建议如何使其工作?

我在之前的许多文章中都知道,不推荐使用Subclassing UIButton,但事实上在Developer's Docs中没有提及NOT子类化它.

subclass uibutton ios

16
推荐指数
4
解决办法
2万
查看次数

如何在图像上绘制(显示)用户位置?iOS版

所以这是我需要在iOS上完成的任务:

在图像上显示用户的当前位置,如下所示:

在此输入图像描述

是的,就像这张图片!

一看一眼就会注意到的事情很少.它倾斜了.它的标题是关闭.你可以看到地平线..!

可以说,

  • 我有这个图像角落的位置坐标.
  • 我有这个图像倾斜的角度.(例如50°)
  • 我有图像的标题角度.(例如-170°北,这意味着它大约10°西南,如果我错了,请纠正我.)
  • 我有缩放级别,如果它在谷歌地图/谷歌地球上,这个图像将被缩放.(例如14个缩放级别 - 20个)

但那就是任务,我需要在这些图像上显示用户位置.就像在"谷歌地球"中一样.

任何人都可以帮我完成这项任务吗?

谢谢大家.:)

iphone geolocation ipad ios ios5

13
推荐指数
1
解决办法
415
查看次数

在SpriteKit中缩放和滚动SKNode

我正在SpriteKit上开发像Scrabble这样的游戏,并且一直停留在Scoble和Scrolling Scrabble Board上.首先让我解释游戏背后的工作:在我的GameScene上我有:

  • 一个名为GameBoard Layer(名为NAME_GAME_BOARD_LAYER)的SKNode子类,包含以下子项:

    A SKNode subclass for Scrabble Board named NAME_BOARD.
    A SKNode subclass for Letters Tile Rack named NAME_RACK.
    
    Run Code Online (Sandbox Code Playgroud)

    Letters Tiles从Tile Rack中挑选并放入Scrabble Board.

这里的问题是,我需要模仿UIScrollView可以实现的缩放和滚动,我认为不能在SKNode上添加.我需要模仿的功能是:

  • 缩放用户双击的精确位置
  • 滚动(尝试PanGestures,以某种方式创建拖拽瓦片的问题)
  • 将Zoomed SKNode保留在特定区域(与UIScrollView一样,将缩放的内容保留在scrollView边界内)

这是我用于缩放的代码,使用UITapGestures:

在我的GameScene.m中

- (void)didMoveToView:(SKView *)view {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
tapGesture.numberOfTouchesRequired = 1;
[self.scene.view addGestureRecognizer:tapGesture];
}

- (void)handleTapGesture:(UITapGestureRecognizer*)recognizer {
if ([self childNodeWithName:NAME_GAME_BOARD_LAYER]) {
    GameBoardLayer *gameBoardLayer = (GameBoardLayer*)[self childNodeWithName:NAME_GAME_BOARD_LAYER];

    SKNode *node = [Utils nodeAt:[recognizer locationInView:self.view]
                        withName:NAME_BOARD
                   inCurrentNode:gameBoardLayer];

    if ([node.name isEqualToString:NAME_BOARD]) {
        [gameBoardLayer handleDoubleTap:recognizer];
    } …
Run Code Online (Sandbox Code Playgroud)

iphone scroll uiscrollview ios sprite-kit

12
推荐指数
1
解决办法
4511
查看次数

如何在iOS上以图形方式实现和显示Sound Amplitude?

任务是显示手机麦克风中的语音幅度,并显示如下幅度:

在此输入图像描述

有人可以指导我如何实现这一目标.

感谢大家.

iphone xcode voice-recording ios

10
推荐指数
1
解决办法
3562
查看次数

在Twitter上分享时,GIF不会制作动画

我创建与动画GIF文件NSArrayUIImage.并将其保存在NSDocumentDirectoryiPhone的相册中.

我面临的问题是,当我在Email Composer或iMessage中打开保存的GIF时,它会动画很好.但是当我通过Twitter分享它时,它没有动画.我尝试通过iPhone上的Twitter应用程序分享并看到一个有趣的事情(下面的ScreenShot)我使用Safari从不同网站下载的GIF在GIF的左上角显示了一个标签'GIF'.虽然我保存的GIF没有.这可能是什么问题?任何人都可以指导我.

在此输入图像描述

以下是创建GIF文件的代码:

float delay = 1.0/15.0; // 15 FPS

NSDictionary *prep = @{
                       (__bridge id)kCGImagePropertyGIFDictionary: @{
                               (__bridge id)kCGImagePropertyGIFDelayTime: @(delay) 
                               }
                       };

//    static NSUInteger kFrameCount = 16;

NSDictionary *fileProperties = @{
                                 (__bridge id)kCGImagePropertyGIFDictionary: @{
                                         (__bridge id)kCGImagePropertyGIFLoopCount: @0 // 0 means loop forever
                                         }
                                 };

CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];

CGImageDestinationRef dst = CGImageDestinationCreateWithURL(url, kUTTypeGIF, [images count], nil);
CGImageDestinationSetProperties(dst, (__bridge CFDictionaryRef)fileProperties);

for (int i=0;i<[images count];i++)
{
        //load anImage from array
        UIImage * …
Run Code Online (Sandbox Code Playgroud)

image gif ios

6
推荐指数
1
解决办法
1587
查看次数

处理超高分辨率图像的最佳方法是什么?

我正在开发一个应用程序,它需要使用分辨率高于(2000 x 2000)的图像,以达到文本清晰度.

我有一个背景图像,我需要在其上显示具有相同分辨率的叠加图像.叠加的数量是可变的,从2到30.

在使用UIImage加载图像时,每个像素需要4个字节,因此如果一个图像的分辨率为3000x3000,则需要最多34 MB的内存,15 MB的2000 x 2000.

这就是问题出现的问题,应用程序在3GS上加载4-5张图像后崩溃,在iPhone 4上加载11-13张图像.

需要将叠加层准确放置在背景图像上.它们就像我们在谷歌地图流量叠加层中所拥有的那样.这并不排除平铺,但使任务相对复杂.

我该如何处理这个问题?

iphone iphone-3gs ios iphone-4 ios5

5
推荐指数
1
解决办法
484
查看次数

Phonegap iOS应用程序屏幕双击滑动

我正在为iOS开发一个phonegap应用程序.当我双击屏幕底部时,主屏幕会向上滑动.这仅在纵向模式下发生.

我试过禁用滚动..但这没有奏效.这是我的HTML代码:

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0 " />
<body>
<div class="mainScreenContent" align="center">
<table>
<form>
<tbody>
<tr >
<td>
<button type="submit" class="largeButton grayGradientEffect">Button 1</button>
</td>
</tr>
<tr>
<td >
<button type="submit" class="largeButton grayGradientEffect" onclick="">Button 2</button>
</td>
</tr>
</tbody>
</form>
</table>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)

这是屏幕截图:

这就是主屏幕的样子:

在此输入图像描述

这是双击底部后的样子:

在此输入图像描述

谢谢大家的帮助.

iphone html5 ios cordova

2
推荐指数
1
解决办法
1128
查看次数

Facebook Wall Post就在Facebook注册iOS- facebook SDK 3.2之后

Facebook SDK 3.2

我需要在使用faceboook登录后在Facebook上发布一个墙贴.

这是我正在使用的代码:

在这里,我打开了Facebook会议:

- (IBAction)FBSignup:(id)sender {
    [[AppDelegate sharedObject] openSession:^(FBSession *session, FBSessionState state, NSError *error) {
        [self sessionStateChanged:session state:state error:error];
    }];
}
Run Code Online (Sandbox Code Playgroud)

在状态变化,我用[self populateUserDetails]填充数据,然后尝试在Facebook墙上发布[self postOnFB],但Facebook墙上没有帖子.

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:

            [self populateUserDetails];
            [self postOnFB];
            break;

        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }

    [[NSNotificationCenter defaultCenter]
     postNotificationName:SCSessionStateChangedNotification
     object:session];

    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
} …
Run Code Online (Sandbox Code Playgroud)

iphone xcode facebook ipad ios

1
推荐指数
1
解决办法
3052
查看次数