下記の例では「Month」と「All」、「Timeline」と「Tag」をそれぞれ排他的に選択させたいが、UISegmentedControlでは複数のグループには分割できない。それぞれのボタンに色をつけることでそれを擬似的に表現したい。
初期状態では「Month」「Timeline」がそれぞれ選択されている。
「All」をタッチすると、「Month」の色が消えて、「All」に色がつく。「Timeline」と「Tag」に変化はない。
さらに「Tag」をタッチすると、同様にボタンの色が変化する。
以下、コード。
- (void)viewWillAppear:(BOOL)animated {
navigationSegment = [[UISegmentedControl alloc] initWithItems:nil];
navigationSegment.segmentedControlStyle = UISegmentedControlStyleBar;
navigationSegment.momentary = YES;
//initialize UISegmentedControl
//UISegmentedControlの初期化
[navigationSegment insertSegmentWithTitle:NSLocalizedString(@"month", @"Month") atIndex:0 animated:NO];
[navigationSegment insertSegmentWithTitle:NSLocalizedString(@"all", @"All") atIndex:1 animated:NO];
[navigationSegment insertSegmentWithTitle:NSLocalizedString(@"sorttime",@"Timeline") atIndex:2 animated:NO];
[navigationSegment insertSegmentWithTitle:NSLocalizedString(@"sorttag",@"Tag") atIndex:3 animated:NO];
[navigationSegment insertSegmentWithImage:[UIImage imageNamed: @"mail2.png"] atIndex:4 animated:NO];
//call controlPressed when UISegmentedControl is pushed
//UISegmentedControlが押されたら、controlPressedメソッドを呼ぶ
[navigationSegment addTarget:self action:@selector(controlPressed:) forControlEvents:UIControlEventValueChanged];
//Initial value: Month and Timeline is ON.
//初期値はMonthがON,TimelineがON
tagOrTime = TIMELINE_FLAG_ON;
allOrMonth = MONTH_FLAG_ON;
//When view is displayed, objectAtIndex(es) are 0, 1, 2, 3, and 4 from the left.
//viewが表示されたときは、objectAtIndexは左から0,1,2,3,4。
[[[navigationSegment subviews] objectAtIndex:0] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
[[[navigationSegment subviews] objectAtIndex:1] setTintColor:nil];
[[[navigationSegment subviews] objectAtIndex:2] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
[[[navigationSegment subviews] objectAtIndex:3] setTintColor:nil];
}
- (void)controlPressed:(id)sender{
int index = navigationSegment.selectedSegmentIndex;
if(index == 2){
tagOrTime = TIMELINE_FLAG_ON;
}else if(index == 3){
tagOrTime = TAG_FLAG_ON;
}else if(index == 0){
allOrMonth = MONTH_FLAG_ON;
}else if(index == 1){
allOrMonth = ALL_FLAG_ON;
}else if(index == 4){
....
}
//Since the turn of Subview of UISegmentedControl changes irregularly, it rearranges from the left.
//UISegmentedControlのSubviewの順番がなぜかコロコロ変わってしまうので、左から並び替える。
NSArray *sortedViews = [navigationSegment.subviews sortedArrayUsingFunction:compareViewsByOrigin context:NULL];
//A flag is changed according to the button pushed now.
//現在押されているボタンに従って、フラグを変更する。
if (tagOrTime == TAG_FLAG_ON) {
[[sortedViews objectAtIndex:2] setTintColor:nil];
[[sortedViews objectAtIndex:3] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
} else {
[[sortedViews objectAtIndex:3] setTintColor:nil];
[[sortedViews objectAtIndex:2] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
}
if (allOrMonth == ALL_FLAG_ON) {
[[sortedViews objectAtIndex:0] setTintColor:nil];
[[sortedViews objectAtIndex:1] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
} else {
[[sortedViews objectAtIndex:1] setTintColor:nil];
[[sortedViews objectAtIndex:0] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
}
// Remove all original segments from the control
// 一旦Subviewをすべて削除
for (id view in navigationSegment.subviews) {
[view removeFromSuperview];
}
// Append sorted and colored segments to the control
// 色を変えたsubviewを付け替える
for (id view in sortedViews) {
[navigationSegment addSubview:view];
}
}
//subviews sort function
//ソート関数
NSInteger static compareViewsByOrigin(id sp1, id sp2, void *context)
{
// UISegmentedControl segments use UISegment objects (private API). But we can safely cast them to UIView objects.
float v1 = ((UIView *)sp1).frame.origin.x;
float v2 = ((UIView *)sp2).frame.origin.x;
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
Thank you, https://goddess-gate.com/dc2/index.php/post/454
iPhoneアプリ「おさいふ」をアップデートしました。ぜひお試しください!
「おさいふ」は、単純なインターフェースで「続けられる家計簿入力」をコンセプトに作成しました。おさいふの入力をネットワーク経由でお友達やご夫婦で共有できること、最低2タップで入力が完了することが大きな特徴です。
(1.2.0でのアップデート)
・入力画面の使い勝手をよくしました。「タグ(摘要)」から、金額のフィールドをタップして、連続で入力できるようにしました。今までは一回一回「完了」ボタンを押さないといけなかったもので。
・おさいふ選択画面で、残高表示されるようにしました。
・リスト画面で、現在どの表示方法を選択しているか、わかりやすい配色にしました。
(1.1.0でのアップデート)
・プリセットボタンに別名を付けられることで、例えばボタンには食事の絵文字、タグ(摘要)には「ランチ」と別々に設定できるようにしました。
起動時に「このアプリを評価してください」とUIAlertにと出したい話。
こういう場合は、didFinishLaunchingWithOptionsにUIAlertについての記述をすれば良い。
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect frameForWindow = [[UIScreen mainScreen] bounds];
window = [[UIWindow alloc] initWithFrame:frameForWindow];
//write about window
//ウインドウについて記載
[window addSubview:navigationController.view];
//From here about UIAlert and rating popup.
//manage displaying UIAlert by NSUserDefaults
//ここからUIAlertについて記載。表示するかどうかはNSUserDefaultsで制御する。
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger executeTime = [userDefaults integerForKey: @"executeTime"];
NSInteger alertDispFlag = [userDefaults integerForKey: @"alertDispFlag"];
executeTime++;
//If this application is started 6 times or more and alertDispFlag == 0, then alert is displayed.
//もし6回以上起動していて、alertDispFlagが0なら表示する
if (executeTime > 5 && alertDispFlag == 0) {
// アラート表示
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title=NSLocalizedString(@"pleaseReview", @"Please Rate");
alertView.message=NSLocalizedString(@"appliciate", @"Please Rate this apps.");
[alertView addButtonWithTitle:NSLocalizedString(@"Review", @"Rate now.")];
[alertView addButtonWithTitle:NSLocalizedString(@"Later", @"Remind me later.")];
[alertView addButtonWithTitle:NSLocalizedString(@"nothanks", @"No, thanks.")];
[alertView show];
[alertView release];
}
[userDefaults setInteger:executeTime forKey: @"executeTime"];
[userDefaults synchronize];
return YES;
}
//UIAlartのデリゲート。UIAlertの動作を記載する。
//delegate to UIAlret
-(void)alertView:(UIAlertView*)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
switch (buttonIndex) {
case 0:
//go to rate page
[userDefaults setInteger: 1 forKey: @"alertDispFlag"];
[userDefaults synchronize];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSLocalizedString(@"reviewURL", @"") ]];
break;
case 1:
break;
case 2:
[userDefaults setInteger: 1 forKey: @"alertDispFlag"];
[userDefaults synchronize];
break;
}
}
review URLは、
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=(数字9桁のapp id)&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software
です。
Arduino uno にethernet shieldを乗っけて、iPhoneアプリのiOSCから、OSCのUDPパケットを受信してArduinoに接続された液晶を変更するスケッチ。
液晶接続のポートですが、最初
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
としてたら液晶が表示されなかったので、下のスケッチのようにしたら動くようになりました。接続ポートに注意。また、UDPの受信コードはExamplesのUDPSendReceiveStringを参考にしました。というかそのまんま使いました。
/*
UDPSendReceive.pde:
*/
#include // needed for Arduino versions later than 0018
#include
#include // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
byte ip[] = { 192 , 168 , 1 , 1 } ; //
unsigned int localPort = 10000; // local port to listen on
// the next two variables are set when a packet is received
byte remoteIp[4]; // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
LiquidCrystal lcd(8, 7, 6, 5, 4, 3, 2);
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0, 0);
Serial.begin(9600);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.available(); // note that this includes the UDP header
if(packetSize)
{
packetSize = packetSize - 8; // subtract the 8 byte header
Serial.print("Received packet of size ");
Serial.println(packetSize);
// read the packet into packetBufffer and get the senders IP addr and port number
Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
char* c = packetBuffer;
if( strcmp(c, "/osc/button1") == 0 ){
lcd.setCursor(0,0);
lcd.print("button 1 pushed");
}
if ( strcmp(c, "/osc/button2") == 0 ){
lcd.setCursor(0,0);
lcd.print("button 2 pushed");
}
Udp.sendPacket( ReplyBuffer, remoteIp, remotePort);
}
delay(500);
}
OpenCV + AVFoundation – First step of AR
カメラからリアルタイムキャプチャして,OpenCVでFFTしたスペクトルをだすプログラム.
ARはこんなところから始まるんでしょう,という例です.
プロジェクトのダウンロード (Xcode Project – Source)
こんな感じのプログラムです.下の方に表示されているのはプレビュー画像,上がスペクトルです.
このプログラムに対して,samurai-appsは一切責任を持ちません.自己責任で,またサンプルとして利用してください.
samurai-appsは本日,iPhone/iPod Touch/iPadアプリ 隠レター・隠Reader をリリースしました.
隠レターは,いわゆる電子透かしアプリです.自分の撮った,あるいはカメラロールにある写真に,自分の指で描いた秘密の画像を埋め込むことができます.埋め込んだ画像は受け取り手の隠レターで抽出することができます.秘密の通信に使いましょう.6月25日までは無料キャンペーンをしておりますので,ダウンロードして頂き,ぜひご感想をお寄せください.
隠Readerは,抽出に特化した無料アプリです。秘密の画像を受け取っても、これさえあればその秘密の画像を見ることができます。
詳しくはこちらから!
–
開発はObjective-Cはもちろんのこと,今回はOpenCVを使って書いています.画像処理はやはりOpenCVに任せてしまうのがいいですね.しかし,iPhone3Gで計算速度を出すのが大変でした.インタフェースにはまだまだ改良の余地がありますが,ぜひ電子透かしの新しい使い方を模索してみてください.
ご好評いただいているCalolog(カロログ) の無料配布版を本日,公開しました.
機能的な制限はありませんが,広告が出ます.
今後ともsamurai-appsをよろしくお願い申し上げます.
Calolog FREE (iTunes)
5秒の強制思考時間のON/OFFを選択できるようになりました.